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

find the safest road

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6911    Accepted Submission(s): 2450

Problem Description
XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1 间的实数(包括0,1),一条从u 到 v 的通道P 的安全度为Safe(P) = s(e1)*s(e2)…*s(ek) e1,e2,ek是P 上的边 ,现在8600 想出去旅游,面对这这么多的路,他想找一条最安全的路。但是8600 的数学不好,想请你帮忙 ^_^
 
Input
输入包括多个测试实例,每个实例包括:
第一行:n。n表示城市的个数n<=1000;
接着是一个n*n的矩阵表示两个城市之间的安全系数,(0可以理解为那两个城市之间没有直接的通道)
接着是Q个8600要旅游的路线,每行有两个数字,表示8600所在的城市和要去的城市
 
Output
如果86无法达到他的目的地,输出"What a pity!",
其他的输出这两个城市之间的最安全道路的安全系数,保留三位小数。
 
Sample Input
3
1 0.5 0.5
0.5 1 0.4
0.5 0.4 1
3
1 2
2 3
1 3
 
 
Sample Output
0.500
0.400
0.500
 

。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。/。

和上一篇差不多,小变形

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm> #define MAXX 1005
#define INF 1000000000
double d[MAXX][MAXX]; int Floyd(int n)
{
int i,j,k;
for(k=; k<n; k++)
for(i=; i<n; i++)
for(j=; j<n; j++)
if(d[i][k] * d[k][j] > d[i][j])
d[i][j] = d[i][k] * d[k][j];
} int main()
{
int n,m,i,j;
//freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF)
{
double tmp;
memset(d,,sizeof(d)); for(i=; i<n; i++)
{
for(j=; j<n; j++)
{
scanf("%lf",&tmp);
d[i][j] = tmp;
}
}
Floyd(n);
scanf("%d",&m);
if(n == )
{
printf("0\n");
continue;
}
int st,ed;
for(i=; i<m; i++)
{
scanf("%d%d",&st,&ed);
if(d[st-][ed-] > )
{
printf("%.3lf\n",d[st-][ed-]);
}
else
{
printf("What a pity!\n");
}
}
}
return ;
}

hdu 1596(Floyd 变形)的更多相关文章

  1. HDU 1596 floyd

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. HDU.1596 find the safest road (Floyd)

    HDU.1596 find the safest road (Floyd) 题意分析 与普通的最短路不太相同,本题有些许的变化. 1. 要找到由i到j最安全的路,故在求解的时候要保证mp[i][j]尽 ...

  3. UVA10048 Audiophobia[Floyd变形]

    UVA - 10048 Audiophobia Consider yourself lucky! Consider yourself lucky to be still breathing and h ...

  4. POJ2253——Frogger(Floyd变形)

    Frogger DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fi ...

  5. hdu 1217 (Floyd变形)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others)   ...

  6. HDU 4034 Graph(Floyd变形——逆向判断)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4034 Problem Description Everyone knows how to calcu ...

  7. HDU 1596 最短路变形

    这道题怎么都是TLE,报警了,先放在这 http://acm.hdu.edu.cn/showproblem.php?pid=1596 #include <iostream> #includ ...

  8. hdu 1596 find the safest road (变形SP && dij+heap)

    Problem - 1596 变形最短路问题,给出邻接矩阵,要求求出给定点对间安全率最大值. 这题可以用dijkstra+heap来做.对于每一个查询,做一次dij即可. 代码如下: #include ...

  9. hdu 1596 find the safest road

    http://acm.hdu.edu.cn/showproblem.php?pid=1596 #include <cstdio> #include <cstring> #inc ...

随机推荐

  1. codereview

    http://www.cnblogs.com/wenhx/p/How-We-Code-Review.htmlhttp://www.cnblogs.com/mindwind/p/5639008.html ...

  2. [转]vs2008安装失败的总结与分享

    转自:http://www.cnblogs.com/rockdean/archive/2010/01/13/1646851.html 今天系统是刚装的,今儿个也不是第一次装系统,也不是第一次装vs20 ...

  3. C# Driver LINQ Tutorial

    1.介绍 该教程涵盖了1.8版本的C#驱动中的LINQ查询.你可能已经阅读最新的C# Driver Tutorial. 2.快速开始 首先,给程序添加下面的using声明 using MongoDB. ...

  4. inupt textarea提示文字(点击消失,不输入恢复)

    <input name="textfield" type="text"  maxlength="20" value="请输入 ...

  5. NSData NSDate NSString NSArray NSDictionary 相互转换

    // NSData NSDate NSString NSArray NSDictionary json NSString *string = @"hello word"; NSDa ...

  6. jquery与服务器交换数据的利器--ajax(异步javascript and xml)

    load() 方法从服务器加载数据,并把返回的数据放入被选元素中. 一.下面的例子把 "demo_test.txt" 文件中 id="p1" 的元素的内容,加载 ...

  7. 花40分钟写一个-CBIR引擎-代码公开

          浏览网页的时候发现一篇不错的文章"用Python和OpenCV创建一个图片搜索引擎的完整指南"http://python.jobbole.com/80860/.作者在浏 ...

  8. Oracle OCCI学习之开篇

    官网:Oracle C++ Call Interface 一.OCCI介绍 Oracle C++ Call Interface(OCCI)是一个用于访问Oracle数据库的高性能且全面的API.基于标 ...

  9. phpcms 04

    首页index.html 首页头条推荐 <div class="col-left"> <div class="news-hot"> &l ...

  10. hdu 4002 Find the maximum

    Find the maximum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...