zoukankan      html  css  js  c++  java
  • Floyd最短路径

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

     1 Problem : 1596 ( find the safest road )     Judge Status : Accepted
     2 RunId : 10374805    Language : C++    Author : l1285556798
     3 Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
     4 
     5 #include<stdio.h>
     6 #include<string.h>
     7 #define maxn 1001
     8 double map[maxn][maxn];
     9 int n,q;
    10 void floyd()
    11 {
    12     for(int k=1;k<=n;k++)
    13         for(int i=1;i<=n;i++)
    14          for(int j=1;j<=n;j++)
    15          if(map[i][j]<map[i][k]*map[k][j])
    16          map[i][j]=map[i][k]*map[k][j];
    17 }
    18 int main()
    19 {
    20     while(scanf("%d",&n)!=EOF)
    21     {
    22         memset(map,0,sizeof(map));
    23         for(int i=1;i<=n;i++)
    24             for(int j=1;j<=n;j++)
    25             scanf("%lf",&map[i][j]);
    26         floyd();
    27         scanf("%d",&q);
    28         while(q--)
    29         {
    30             int a,b;
    31             scanf("%d%d",&a,&b);
    32             if(!map[a][b])
    33                 printf("What a pity!
    ");
    34             else
    35                 printf("%.3lf
    ",map[a][b]);
    36         }
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    注册表开启或关闭ie浏览器-局域网设置-自动监测设置
    关于win32接口文档位置
    网站添加天气预报插件
    json
    re正则
    配置文件
    logging日志模块
    hashlib加密
    sys模块
    os模块
  • 原文地址:https://www.cnblogs.com/lyf123456/p/3618884.html
Copyright © 2011-2022 走看看