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 ...
随机推荐
- 关于小程序报错 缺少文件,错误信息:error: iconPath=../images/home.png, file not found
事实上在小程序中,虽然你的image文件夹是和你index文件夹的父级文件夹并行的文件夹,但是你如果引用的时候,不用去遵循 ../ 或者 ./因为在小程序当中他根本不识别.所以要引用的话 ...
- FineReport----日期处理
日期处理:http://help.finereport.com/doc-view-819.html DAYSOFMONTH(date):返回当日的该月天数 DATEDELTA(Today(),-1): ...
- 9.JavaScript简单计算器的实现
1.难点,怎么获取标签的值,注意点,获取到的值都是string类型,还要转换 var num1 = parseInt(document.getElementById("num1") ...
- Java 之Object 类
Object 类: 所有类的根类, 是不断向上抽取而来, 具备着所有对象都具备的共性内容. 常用共性方法 boolean equals(Object obj) : 判断两个对象是否相等. 默认比较的是 ...
- 原!mysql5.6 存储过程 批量建表
由于业务需求,需要按天分表,因此写了个存储过程,根据时间生成表. 根据createTime 的时间,以及 while循环的变量设置范围,生成该指定日期及之后的多张表. BEGIN ); ); ; '; ...
- ubuntu14 编译安装(升级)g++
编译安装(升级)g++ ubuntu14自带的g++为4.8.4,不支持c++11.现要将g++升至5.2.0 1.下载安装: 参考https://www.cppfans.org/1719.html ...
- 洛谷 P2467 [SDOI2010]地精部落
洛谷 我讲的应该没有这个[https://www.luogu.org/blog/user55639/solution-p2467]清楚. 贴个代码算了: #include <bits/stdc+ ...
- git学习------>写给 Git 初学者的7个建议
PS:本文转载于(http://blog.jobbole.com/50603/),本文由 伯乐在线 - 吴鹏煜 翻译. 英文出处:(http://sixrevisions.com/web-develo ...
- git发布代码到github过程和常见错误
在对git有了基本了解之后,并且常常看到很多人在github上发布代码和开源项目时,就会想如何也把自己的代码发布到github上,并能够不断的跟踪版本变化. 现在就有几个想要做的事. 一.如何把自己已 ...
- corethink功能模块探索开发(十七)opencmf.php 配置文件
图样: opencmf.php存在于每个模块的根目录,是模块配置文件. 能进行持久化配置参数保存,一开始我以为是写文件或者做缓存,后来在数据库中发现admin_module表,存储了每个模块的配置参数 ...