【解题报告】【HDOJ1596】【Floyd最短路】find the safest road
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1596
1 #include<stdio.h> 2 #include<string.h> 3 #define max(a,b) (a>b?a:b) 4 double map[1005][1005]; 5 int n; 6 int main() 7 { 8 int t,i,j,k; 9 //freopen("1.txt","r",stdin); 10 while(scanf("%d",&n)!=EOF) 11 { 12 13 for(i=1;i<=n;i++) 14 { 15 for(j=1;j<=n;j++) 16 scanf("%lf",&map[i][j]); 17 } 18 19 for(k=1;k<=n;k++) 20 { 21 for(i=1;i<=n;i++) 22 { 23 for(j=1;j<=n;j++) 24 map[i][j]=max(map[i][k]*map[k][j],map[i][j]); 25 } 26 } 27 scanf("%d",&t); 28 while(t--) 29 { 30 scanf("%d%d",&i,&j); 31 if(map[i][j]) 32 printf("%0.3lf\n",map[i][j]); 33 else printf("What a pity!\n"); 34 } 35 } 36 return 0; 37 }