hdu1596 find the safest road - floyd
2017-08-04 14:42:56
writer:pprp
题意:
第一行:n。n表示城市的个数n<=1000;
接着是一个n*n的矩阵表示两个城市之间的安全系数,(0可以理解为那两个城市之间没有直接的通道)
接着是Q个8600要旅游的路线,每行有两个数字,表示8600所在的城市和要去的城市
Output
其他的输出这两个城市之间的最安全道路的安全系数,保留三位小数。
算法分析:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath> using namespace std; const int maxn = ;
double dis[maxn][maxn];
int n; double MAX(double a,double b)
{
return a > b ?a:b;
} void floyd()
{
for(int k = ; k <= n; k++)
for(int i = ; i <= n ; i++)
for(int j = ; j <= n ; j++)
{
dis[i][j] = MAX(dis[i][j],dis[i][k]*dis[k][j]);
}
} int main()
{
while(scanf("%d",&n) != EOF)
{
memset(dis,,sizeof(dis)); for(int i = ; i <= n ; i++ )
for(int j = ; j <= n; j++)
scanf("%lf",&dis[i][j]); floyd(); int num;
int b, e;
scanf("%d",&num);
for(int i = ; i < num ; i++)
{
cin >> b >> e;
if(dis[b][e])
printf("%.3lf\n",dis[b][e]);
else
printf("What a pity!\n");
}
} return ;
}
hdu1596 find the safest road - floyd的更多相关文章
- HDU.1596 find the safest road (Floyd)
HDU.1596 find the safest road (Floyd) 题意分析 与普通的最短路不太相同,本题有些许的变化. 1. 要找到由i到j最安全的路,故在求解的时候要保证mp[i][j]尽 ...
- hdu1569find the safest road(floyd变形求最大安全值)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu1596find the safest road(floyd)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU1596 find the safest road
find the safest road XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1 间的实数(包括0,1),一 ...
- 杭电 1595 find the safest road
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 1596 find the safest road (最短路)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU——1596find the safest road(邻接矩阵+优先队列SPFA)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 杭电1596 find the safest road
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdoj 1596 find the safest road【最短路变形,求最大安全系数】
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
随机推荐
- JZOJ.5273【NOIP2017模拟8.14】亲戚
Description
- 【BZOJ4773】负环 倍增Floyd
[BZOJ4773]负环 Description 在忘记考虑负环之后,黎瑟的算法又出错了.对于边带权的有向图 G = (V, E),请找出一个点数最小的环,使得 环上的边权和为负数.保证图中不包含重边 ...
- iOS tabbar 属性
1.设置tabbar背景颜色 NSArray *controllers = [NSArray arrayWithObjects:nav_main,nav_channle,nav_me, nil]; _ ...
- 推荐10 个短小却超实用的 JavaScript 代码段
1. 判断日期是否有效 JavaScript中自带的日期函数还是太过简单,很难满足真实项目中对不同日期格式进行解析和判断的需要.jQuery也有一些第三方库来使日期相关的处理变得简单,但有时你可能只需 ...
- sql语句(mysql中json_contains、json_array的使用)
https://blog.csdn.net/qq_35952946/article/details/79131488 https://www.jianshu.com/p/455d3d4922e1 1. ...
- WCF引用 代码
方法1: using (ChannelFactory<ICommonService> channelFactory = new ChannelFactory<ICommonServi ...
- 转+总结!! 关于jsp页面取值方式
1. 前台往后台传值,通过提交表单,在后台有set,get方法,可以直接取到.如果通过request.getParameter(paramName) 去获取通过会报空指针异常. 其中requ ...
- CNI IPAM插件分析 --- 以hostlocal为示例
skel.CmdArgs数据结构如下所示: type CmdArgs struct { ContainerID string Netns string IfName string Args strin ...
- 我的Android进阶之旅------>Android编译错误java.util.zip.ZipException: duplicate entry的解决方法
今天在Android Studio中把另外一个项目引入当前项目,编译的时候出现了java.util.zip.ZipException: duplicate entry错误. 错误如下所示: FAILU ...
- PAT 1119 Pre- and Post-order Traversals [二叉树遍历][难]
1119 Pre- and Post-order Traversals (30 分) Suppose that all the keys in a binary tree are distinct p ...