HDU 1596:find the safest road
2017-04-03 14:54
363 查看
find the safest road
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 12379 Accepted Submission(s): 4407
点击打开题目链接
Problem Description
XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1 间的实数(包括0,1),一条从u 到 v 的通道P 的安全度为Safe(P) = s(e1)*s(e2)…*s(ek) e1,e2,ek是P 上的边 ,现在8600 想出去旅游,面对这这么多的路,他想找一条最安全的路。但是8600 的数学不好,想请你帮忙 ^_^
Input
输入包括多个测试实例,每个实例包括:
第一行:n。n表示城市的个数n<=1000;
接着是一个n*n的矩阵表示两个城市之间的安全系数,(0可以理解为那两个城市之间没有直接的通道)
接着是Q个8600要旅游的路线,每行有两个数字,表示8600所在的城市和要去的城市
Output
如果86无法达到他的目的地,输出"What a pity!",
其他的输出这两个城市之间的最安全道路的安全系数,保留三位小数。
Sample Input
3
1 0.5 0.5
0.5 1 0.4
0.5 0.4 1
3
1 2
2 3
1 3
Sample Output
0.500
0.400
0.500
Flody算法模板题目。
#include <iostream> #include <stdio.h> #include <string.h> #include <vector> using namespace std; double mostsafe[1001][1001];//用于存放由i到j的最大安全系数 int N,M; void Floyd() { int i,j,k; for(k = 1; k <= N; k++) { for(i = 1; i <= N; i++) for(j = 1; j <= N; j++) /*如果i到k的安全系数+k到j的安全 系数比i到j的大,那么就经过k到j*/ if(i != j) { if(mostsafe[i][j] < mostsafe[i][k]*mostsafe[k][j]) mostsafe[i][j] = mostsafe[i][k]*mostsafe[k][j]; } } } int main() { int i,j,start,eend; while(~scanf("%d",&N)) { for(i = 1; i <= N; i++) for(j = 1; j <= N; j++) { scanf("%lf",&mostsafe[i][j]); } Floyd(); scanf("%d",&M); while(M--) { scanf("%d%d",&start,&eend); if(mostsafe[start][eend] == 0) printf("What a pity!\n"); else printf("%.3lf\n",mostsafe[start][eend]); } } return 0; }
相关文章推荐
- hdu 1596 find the safest road
- (阶段三 dijkstra1.4)HDU 1596 find the safest road(最短路的变形题:求乘积,求最大值)
- HDU 1596 find the safest road
- hdu 1596 find the safest road (最短路)
- HDU 1596 find the safest road(SPFA)
- hdu1596 find the safest road
- HDU 1596 find the safest road
- hdu 1596 find the safest road
- HDU-1596-find the safest road
- hdu1596——find the safest road
- HDU 1596 find the safest road
- hdu-1596 find the safest road(SPFA做法)
- hdu 1596 find the safest road
- hdu 1596 find the safest road
- hdu 1596 find the safest road
- hdu 1596 find the safest road (floyd)
- HDU 1596----find the safest road
- 1596 hdu find the safest road
- hdu 1596 find the safest road(待改正)且已修改
- hdu 1596 find the safest road(最短路求最大值的题目,有两种稍微不同的处理方式)