所以说啊 人家英国5岁小孩就会写程式才是对的
虽然我推文讲过了
之前修张耀文的算法,第一堂课就放海角七号,告诉我们邮差怎么规划路径
可见与邮差工作最相关的就是算法
路径规划的精神就是走cost最低的路线,走过的尽量不要重复
最常用的就是A*算法
嫌太难,再不然可以考Dijkstra算法,但是要背出 pseudo code
背科是文组拿手,这个只有短短十几行,应该不难
贴在这边,不用谢我
function Dijkstra(Graph, source):
create vertex set Q
for each vertex v in Graph: // Initialization
dist[v] ← INFINITY // Unknown distance from source to v
prev[v] ← UNDEFINED // Previous node in optimal path from source
add v to Q // All nodes initially in Q (unvisited nodes)
dist[source] ← 0 // Distance from source to source
while Q is not empty:
u ← vertex in Q with min dist[u] // Source node will be selected first
remove u from Q
for each neighbor v of u: // where v is still in Q.
alt ← dist[u] + length(u, v)
if alt < dist[v]: // A shorter path to v has been found
dist[v] ← alt
prev[v] ← u
return dist[], prev[] 1 function Dijkstra(Graph, source):
再不然,也可以考怎么操作Google地图。