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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
腾讯CDC
Y
Y Combinator Blog
L
LangChain Blog
B
Blog
U
Unit 42
P
Proofpoint News Feed
G
Google Developers Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 【当耐特】
WordPress大学
WordPress大学
月光博客
月光博客
Vercel News
Vercel News
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 叶小钗

博客园 - 北叶青藤

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}")