码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1596 find the safest road

时间:2014-04-28 01:18:06      阅读:597      评论:0      收藏:0      [点我收藏+]

标签:com   class   blog   http   code   div   img   style   string   tar   art   

http://acm.hdu.edu.cn/showproblem.php?pid=1596

bubuko.com,布布扣
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define maxn 1001
 5 using namespace std;
 6 
 7 double g[maxn][maxn];
 8 int dis[maxn];
 9 bool vis[maxn];
10 int n,a,b;
11 
12 void floyd()
13 {
14     for(int k=1; k<=n; k++)
15     {
16         for(int i=1; i<=n; i++)
17         {
18             if(g[i][k]==0) continue;
19             for(int j=1; j<=n; j++)
20             {
21                 if(g[i][j]<g[i][k]*g[k][j])
22                 {
23                     g[i][j]=g[i][k]*g[k][j];
24                 }
25             }
26         }
27     }
28 }
29 
30 int main()
31 {
32     while(scanf("%d",&n)!=EOF)
33     {
34         for(int i=1; i<=n; i++)
35         {
36             for(int j=1; j<=n; j++)
37             {
38                 scanf("%lf",&g[i][j]);
39             }
40         }
41         floyd();
42         int m;
43         scanf("%d",&m);
44         for(int i=1; i<=m; i++)
45         {
46             scanf("%d%d",&a,&b);
47             if(g[a][b]!=0)
48                 printf("%.3lf\n",g[a][b]);
49             else
50                 printf("What a pity!\n");
51         }
52     }
53     return 0;
54 }
View Code

 

hdu 1596 find the safest road,布布扣,bubuko.com

hdu 1596 find the safest road

标签:com   class   blog   http   code   div   img   style   string   tar   art   

原文地址:http://www.cnblogs.com/fanminghui/p/3695185.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!