hdu1569find the safest road(floyd变形求最大安全值)
find the safest road
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7845 Accepted Submission(s): 2786
第一行:n。n表示城市的个数n<=1000;
接着是一个n*n的矩阵表示两个城市之间的安全系数,(0能够理解为那两个城市之间没有直接的通道)
接着是Q个8600要旅游的路线,每行有两个数字。表示8600所在的城市和要去的城市
其它的输出这两个城市之间的最安全道路的安全系数,保留三位小数。
3
1 0.5 0.5
0.5 1 0.4
0.5 0.4 1
3
1 2
2 3
1 3
0.500
0.400
0.500
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
#define maxn 1005
#define inf 0x3f3f3f3f
double d[maxn][maxn];
int n;
void floyd(){
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++){
d[i][j]=max(d[i][j],d[i][k]*d[k][j]);
}
}
int main()
{
int q;
int a,b;
// freopen("in.txt","r",stdin);
while(~scanf("%d",&n)&&n){
memset(d,inf,sizeof d);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
scanf("%lf",&d[i][j]);
floyd();
scanf("%d",&q);
for(int i=0;i<q;i++){
scanf("%d%d",&a,&b);
if(d[a][b])
printf("%.3lf\n",d[a][b]);
else puts("What a pity!");
}
}
}
hdu1569find the safest road(floyd变形求最大安全值)的更多相关文章
- HDU.1596 find the safest road (Floyd)
HDU.1596 find the safest road (Floyd) 题意分析 与普通的最短路不太相同,本题有些许的变化. 1. 要找到由i到j最安全的路,故在求解的时候要保证mp[i][j]尽 ...
- 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 - floyd
2017-08-04 14:42:56 writer:pprp 题意: Problem Description XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每 ...
- hdu 1596 find the safest road (变形SP && dij+heap)
Problem - 1596 变形最短路问题,给出邻接矩阵,要求求出给定点对间安全率最大值. 这题可以用dijkstra+heap来做.对于每一个查询,做一次dij即可. 代码如下: #include ...
- hdoj 1596 find the safest road【最短路变形,求最大安全系数】
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDOJ find the safest road 1596【最短路变形】
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 杭电 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(Floyd 变形)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...
- UVA10048 Audiophobia[Floyd变形]
UVA - 10048 Audiophobia Consider yourself lucky! Consider yourself lucky to be still breathing and h ...
随机推荐
- Oracle中查询各种对象的方法小结
--查看当前库中的所有表select * from all_tables a where a.table_name='INFOCODE_P20081'--查看表结构select * from all_ ...
- 如何将UISearchBar上"Cancel"按钮改为”取消“?
别说话,直接上代码 for (id obj in [searchBar subviews]) { if ([obj isKindOfClass:[UIView class]]) { ...
- jQuery格式化时间插件formatDate
一.不传时间 $.formatDate("yyyy-MM-dd HH:mm:ss"); 二.传时间 $.formatDate("yyyy-MM-dd HH:mm:ss ...
- 2016年会成为Java EE微服务年吗?
原文 http://www.infoq.com/cn/news/2016/02/javaee-microservices 进入2016年时间还不是很长,让我们回顾下去年年底的一个预言.去年12月,来 ...
- hdu1172猜数字
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1172 题目 猜数字 Time Limit: 20000/10000 MS (Java/Others) ...
- 西门子PLC学习笔记七-(位逻辑指令)
位逻辑指令处理的对象为二进制位信号.存储在状态字"RLO"中. 1.触点与线圈指令 1)常开触点 在PLC中规定:操作数为1,则常开触点"动作(闭合)":操作数 ...
- [译]TCP和UDP的区别
译者:华科小涛:http://www.cnblogs.com/hust-ghtao/ 最近开始学习计算机网络的知识,找了些英文的资料,翻译过来,一是为了深入学习网络,也是为了锻炼自己看英文文档的能力. ...
- 通过cmd命令安装、卸载、启动和停止Windows Service(InstallUtil.exe)-大壮他哥
步骤: 1.运行--〉cmd:打开cmd命令框 2.在命令行里定位到InstallUtil.exe所在的位置 InstallUtil.exe 默认的安装位置是在C:/Windows/Microsoft ...
- 【笔记】《通俗详细地讲解什么是P和NP问题》的概念记录
1问题规模: 要计算或解决一个问题,该问题通常有一个大小规模,用n表示. 2算法的时间复杂度 计算次数与n的关系函数.(因为计算次数隐含时间). 3多项式时间复杂度 所有形如a*n^k+b*n^(k- ...
- 摘记:IIS长时间任务超时处理
1.如果是在客户端调用Webservice,首先设置客户端超时, SoapHttpClientProtocol.Timeout = 3600 * 1000;//单位为秒,这是设置了一个小时 2.如果站 ...