zoj 3166 Lazy Tourist(最短路Floyd)
2010-11-28 22:53
330 查看
求出到达hotel的环的最短路。
因为是求最后再到达hotel的最小环, 所以初始化都为INT_MAX
单向的路,我很纠结 = =。。。
其他就很水了。
因为是求最后再到达hotel的最小环, 所以初始化都为INT_MAX
单向的路,我很纠结 = =。。。
其他就很水了。
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <memory.h> #include <limits.h> using namespace std; int main(void) { int map[110][110]; int n,c,m,from,to,len; int hotel[110]; while( cin >> n >> c ) { for(int i=0; i<=n; i++) for(int k=0; k<=n; k++) map[i][k] = INT_MAX; for(int i=1; i<=c; i++) cin >> hotel[i]; cin >> m; int sum = INT_MAX; for(int i=0; i<m; i++) { cin >> from >> to >> len; map[from][to] = len; //map[to][from] = len is wrong. Single way. } for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) for(int k=1; k<=n; k++) if( map[j][i] != INT_MAX && map[i][k] != INT_MAX && map[j][k] > map[j][i] + map[i][k] ) map[j][k] = map[j][i] + map[i][k]; int result = 0; for(int i=1; i<=c; i++) if( map[hotel[i]][hotel[i]] < sum ) // Find the smallest one. { sum = map[hotel[i]][hotel[i]]; result = hotel[i]; } if( result ) cout << result << endl; else cout << "I will nerver go to that city!" << endl; } return 0; }
相关文章推荐
- zoj 3166 Lazy Tourist 最短路 floyd
- ZOJ 3166 Lazy Tourist 最短路floyd模版题
- ZOJ 3166 Lazy Tourist 最短路floyd模版题
- zoj 1221 Risk 最短路 floyd
- zoj_3166_floyd_好久没打还翻车一次_丢人
- ZOJ - 3166 Lazy Tourist
- zoj 1232(Floyd预处理 + 状态图上的最短路(好题))
- ZOJ-1456 Minimum Transport Cost 最短路floyd路径输出
- ZOJ 3166 Lazy Tourist
- hdu 1385(zoj 1456)Minimum Transport Cost(最短路,输出路径,Floyd实现)
- zoj 1092 Arbitrage(最短路,floyd)
- NEFU 663 Emergency 最短路 floyd
- poj_1125 Floyd最短路
- zoj2750 Idiomatic Phrases Game ——最短路入门题_Dijkstra算法
- 图论算法 最短路 Floyd
- 最短路——Floyd
- HDOJ 1385 Minimum Transport Cost (最短路 Floyd & 路径记录)
- ZOJ 1082 floyd
- POJ_1125_Stockbroker Grapevine(Floyd求最短路)
- HDU 1690 最短路 FLOYD