标签:desc out find 输入 bsp BMI amp for style
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16965 Accepted Submission(s): 5876
题意:给出一个矩阵,里面两个城市之间的安全系数,之后给出数对城市,要求输出最大的安全系数
题解:floyd入门。
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int INF=0x3f3f3f3f; 4 double a[1005][1005]; 5 int n; 6 void floyd() { 7 for(int k=1; k<=n; k++) { 8 for(int i=1; i<=n; i++) { 9 for(int j=1; j<=n; j++) { 10 a[i][j]=max(a[i][j],a[i][k]*a[k][j]); 11 } 12 } 13 } 14 } 15 int main() { 16 17 while(~scanf("%d",&n)) 18 { 19 memset(a,0,sizeof(a)); 20 for(int i=1;i<=n;i++) 21 { 22 for(int j=1;j<=n;j++) 23 { 24 scanf("%lf",&a[i][j]); 25 } 26 } 27 floyd(); 28 int q; 29 scanf("%d",&q); 30 while(q--) 31 { 32 int x,y; 33 scanf("%d %d",&x,&y); 34 if(a[x][y]==0)printf("What a pity!\n"); 35 else 36 printf("%.3lf\n",a[x][y]); 37 } 38 } 39 return 0; 40 }
hdu1596find the safest road(floyd)
标签:desc out find 输入 bsp BMI amp for style
原文地址:https://www.cnblogs.com/fqfzs/p/9858511.html