首页 > 其他 > 详细

find the safest road(弗洛伊德)

时间:2014-07-09 23:41:33      阅读:445      评论:0      收藏:0      [点我收藏+]

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

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int n;
int ss,ee;
double map[1002][1002];
void F()
{
    for(int k=1;k<=n;k++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int i=1;i<=n;i++)
            {
                if(map[j][k]*map[k][i]>map[j][i])
                    map[j][i]=map[j][k]*map[k][i];
            }
        }
    }

}
int main()
{
    double t;
    int Q;
    int x,y;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                scanf("%lf",&t);
                map[i][j]=t;
            }
        }
        F();
        scanf("%d",&Q);
        while(Q--)
        {
            scanf("%d%d",&x,&y);
            if(map[x][y]==0)
                printf("What a pity!\n");
            else printf("%.3lf\n",map[x][y]);
        }
    }
    return 0;
}

 

find the safest road(弗洛伊德),布布扣,bubuko.com

find the safest road(弗洛伊德)

原文:http://www.cnblogs.com/zhangmingcheng/p/3812643.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!