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

推荐订阅源

量子位
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
Lohrmann on Cybersecurity
V
Visual Studio Blog
Cyberwarzone
Cyberwarzone
D
Docker
The Hacker News
The Hacker News
C
CERT Recently Published Vulnerability Notes
Vercel News
Vercel News
Project Zero
Project Zero
S
Schneier on Security
aimingoo的专栏
aimingoo的专栏
I
Intezer
腾讯CDC
M
MIT News - Artificial intelligence
Hugging Face - Blog
Hugging Face - Blog
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Vulnerabilities – Threatpost
G
Google Developers Blog
N
Netflix TechBlog - Medium
The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
A
Arctic Wolf
S
Securelist
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
Recent Announcements
Recent Announcements
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 热门话题
T
Threatpost
Latest news
Latest news
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
The GitHub Blog
The GitHub Blog
T
Tor Project blog
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}")