惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
P
Privacy International News Feed
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 叶小钗
F
Fortinet All Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 最新话题
AWS News Blog
AWS News Blog
Engineering at Meta
Engineering at Meta
Attack and Defense Labs
Attack and Defense Labs
Recent Announcements
Recent Announcements
Recent Commits to openclaw:main
Recent Commits to openclaw:main
PCI Perspectives
PCI Perspectives
Cloudbric
Cloudbric
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
IT之家
IT之家
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
J
Java Code Geeks
M
MIT News - Artificial intelligence
Cisco Talos Blog
Cisco Talos Blog
V2EX - 技术
V2EX - 技术
Webroot Blog
Webroot Blog
Microsoft Security Blog
Microsoft Security Blog
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
G
Google Developers Blog
W
WeLiveSecurity
罗磊的独立博客
P
Privacy & Cybersecurity Law Blog
阮一峰的网络日志
阮一峰的网络日志
A
About on SuperTechFans
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
T
Tailwind CSS Blog
V
Visual Studio Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Secure Thoughts
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
Google DeepMind News
Google DeepMind News
Google DeepMind News
Google DeepMind News
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Full Disclosure
Blog — PlanetScale
Blog — PlanetScale
The Last Watchdog
The Last Watchdog
P
Proofpoint News Feed

博客园 - 北叶青藤

2096. Step-By-Step Directions From a Binary Tree Node to Another Find path from root to a target node in Binary Tree When Dijkstra Algorithm Should be Use? 1188. Design Bounded Blocking Queue 1115. Print FooBar Alternately 1114. Print in Order 1242. Web Crawler Multithreaded Python Multi-threading bot ip Log Rate Limiter Same Word of HTML Labels Most Frequent Call Chain remove prefix in a words list 1102. Path With Maximum Minimum Value Property Booking Optimizer minimum number 755. Pour Water Keyword Tagging in Reviews with Overlapping Matches Retryer Function Implementation 1125. Smallest Sufficient Team Print the terrain Split stay Task scheduling problem 845. Longest Mountain in Array 723. Candy Crush 1539. Kth Missing Positive Number 1650. Lowest Common Ancestor of a Binary Tree III 424. Longest Repeating Character Replacement 843. Guess the Word 551. Student Attendance Record I
滑雪问题
北叶青藤 · 2026-02-20 · via 博客园 - 北叶青藤

是一个滑雪选手从高山上往下滑,会遇到不同的checkpoint,每一个checkpoint有自己的point,然后每个edge有distance。经过每一个checkpoint所得到的score是通过一个包含point和distance的式子算出来的(比如2 * point +distance之类的)。最终求从最高点往下滑能得到的最大score是多少

 1 from collections import deque
 2 
 3 def calculate_max_scores(points, graph, start_node):
 4     max_scores = {node: -float('inf') for node in points}
 5     
 6     if start_node in max_scores:
 7         max_scores[start_node] = 2 * points[start_node]
 8 
 9     queue = deque([start_node])
10     
11     while queue:
12         u = queue.popleft()
13         if u in graph:
14             for v, dist in graph[u]:
15                 new_score = max_scores[u] + (2 * points[v] + dist)
16                 if new_score > max_scores[v]:
17                     max_scores[v] = new_score
18                     queue.append(v)
19                     
20     return max_scores
21 
22 if __name__ == "__main__":
23     points_data = {
24         'A': 5, 'B': 7, 'C': 6, 'D': 2, 
25         'E': 1, 'F': 7, 'H': 7, 'I': 3, 'J': 2
26     }
27 
28     graph_data = {
29         'A': [('B', 2), ('C', 3)],
30         'B': [('D', 5), ('E', 6)],
31         'C': [('E', 4), ('F', 4)],
32         'D': [('H', 7)],
33         'E': [('H', 6)],
34         'F': [('J', 3)],
35         'H': [('I', 1), ('J', 2)],
36         'I': [],
37         'J': []
38     }
39 
40     results = calculate_max_scores(points_data, graph_data, 'A')
41 
42     print("--- 节点最大得分统计 ---")
43     for node, score in results.items():
44         if score != -float('inf'):
45             print(f"节点 {node}: {score}")
46             
47     print("\n--- 最终目标 ---")
48     final_max = max(results['I'], results['J'])
49     print(f"到达 I 或 J 的最高分是: {final_max}")