Dijksitra算法求最短路仅仅适用于不存在右边是负权的情况(Bellman-Ford算法没有这一个限制)。主要特点是从起点为中心向外层层扩展,直到扩展到终点为止。最短路的最优子结构性质即一个最短路路径中经过的所有点这条路均是其最短路。(反证法易证)Dijkstra基本思路:
①找到最短距离已经确定的顶点,从它出发更新相邻顶点的最短距离
②此后不需要再关心1中的”最短距离已经确定的顶点”在最开...
分类:
编程语言 时间:
2015-03-05 23:46:57
阅读次数:
200
Problem Description在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗?Input输入包括多组数据。每组数据第一行是两个整数N、M(N<=100,M<=10000),N表示成都的大街上有几个路口,标号为1的路口是商店所在地,标号...
分类:
其他好文 时间:
2015-03-05 00:23:23
阅读次数:
225
单源最短路问题是固定一个起点s,求它到所有点的最短路的问题。Bellman-Ford算法可以用于边权为负的情况而不像Dijkstra只适用于边权为正的情况(有负圈返回错误),但是其效率比较低。记从起点s出发到顶点i的最短距离为的d[i] 那么
d[i] = min(d[j]+(j->i)|其中#include
#include
#include <algori...
分类:
编程语言 时间:
2015-03-04 22:44:49
阅读次数:
217
ArbitrageTime Limit:1000MSMemory Limit:65536KTotal Submissions:16652Accepted:7004DescriptionArbitrage is the use of discrepancies in currency exchange...
分类:
其他好文 时间:
2015-03-03 18:27:07
阅读次数:
178
WormholesTime Limit:2000MSMemory Limit:65536KTotal Submissions:33008Accepted:12011DescriptionWhile exploring his many farms, Farmer John has discovere...
分类:
其他好文 时间:
2015-03-02 11:03:12
阅读次数:
159
Currency ExchangeTime Limit:1000MSMemory Limit:30000KTotal Submissions:21349Accepted:7653DescriptionSeveral currency exchange points are working in ou...
分类:
其他好文 时间:
2015-03-01 16:59:46
阅读次数:
164
Problem Description
Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 British pound, 1 British pound buys 10.0 F...
分类:
编程语言 时间:
2015-02-18 09:37:05
阅读次数:
386
Problem Description
某省自从实行了很多年的畅通工程计划后,终于修建了很多路。不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多。这让行人很困扰。
现在,已知起点和终点,请你计算出要从起点到终点,最短需要行走多少距离。
Input
本题目包含多组数据,请处理到文件结束。
每组数据第一行包含两个正整数N和M(0<N<200,0<M<1000),分别代表现有城镇的数目和已修建的道路的数目。城镇分别以0~N-1编号。
...
分类:
编程语言 时间:
2015-02-18 09:34:55
阅读次数:
201
Wormholes
Description
While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to it...
分类:
其他好文 时间:
2015-02-13 11:41:25
阅读次数:
145
F - Wormholes
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64u
SubmitStatus
Description
While exploring his many farms, Farmer John has discovered a number of...
分类:
其他好文 时间:
2015-02-11 14:43:04
阅读次数:
260