单源最短路问题是固定一个起点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
传送门:http://poj.org/problem?id=1860
题目:
Currency Exchange
Time Limit:1000MS
Memory Limit:30000KB
64bit IO Format:%I64d & %I64u
SubmitStatus
Description
Sev...
分类:
其他好文 时间:
2015-02-11 09:23:11
阅读次数:
156
上一节我们写了Bellman-Ford算法解决负权边的问题:
邻接表存储图:
n个顶点,m条边。
数组实现邻接表。对每一条边进行1-m编号。用u,v,w三个数组来记录每条边的信息,即u[i],v[i],w[i]表示第i条边是从第 u[i]号顶点到v[i]号顶点且权值为w[i].
first数组的1-n号单元格分别用来存储1-n号顶点的第一条边的编号,初始的时候因...
分类:
其他好文 时间:
2015-02-03 23:09:03
阅读次数:
457