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

find the safest road(弗洛伊德)

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

标签:style   blog   http   color   os   for   

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(弗洛伊德)

标签:style   blog   http   color   os   for   

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

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