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 ...
随机推荐
- Android之ksoap2-android详解与调用天气预报Webservice完整实例
Google为Android平台开发Web Service客户端提供了ksoap2-android项目,在这个网址下载开发包http://code.google.com/p/ksoap2-androi ...
- python-Day3-set 集合-counter计数器-默认字典(defaultdict) -可命名元组(namedtuple)-有序字典(orderedDict)-双向队列(deque)--Queue单项队列--深浅拷贝---函数参数
上节内容回顾:C语言为什么比起他语言块,因为C 会把代码变异成机器码Pyhton 的 .pyc文件是什么python 把.py文件编译成的.pyc文件是Python的字节码, 字符串本质是 字符数组, ...
- 知识普及:iOS7搭载新定位技术iBeacon
摘自:http://iphone.91.com/tutorial/jcjc/131023/21619035.html 在2013年六月举行的WWDC上,作为iOS 7中最重要的新特性之一,苹果正式对外 ...
- CentOS 6.2 二进制安装apache2.4.3出现configure: error: APR-util not found. Please read the documentation的解决方
CentOS 6.2 二进制安装apache2.4.3出现configure: error: APR-util not found. Please read the documentation的解决方 ...
- soundPool播放短、频、快的声音
package com.example.soundpool; import android.media.AudioManager; import android.media.SoundPool; im ...
- NHibernate - HQL - 添加和更改
添加: /// <summary> /// 等待乙方做出回应 A /// </summary> private void button2_Click_1(object send ...
- Apache Flink
Flink 剖析 1.概述 在如今数据爆炸的时代,企业的数据量与日俱增,大数据产品层出不穷.今天给大家分享一款产品—— Apache Flink,目前,已是 Apache 顶级项目之一.那么,接下来, ...
- 配置用户范围settings.xml
Maven用户可以选择配置<<MavenHome>>/conf/settings.xml或者<<UserHome>>/.m2/settings.xml. ...
- android绑定Service失败原因
今天抄一个代码,学习Service,中间Service的绑定一直是失败的. bindService返回false 上网查询的话都是一些,比如说TabHost的问题 发现和自己的问题不一样. 最后想了想 ...
- State Design Pattern 状态设计模式
设置好内部状态,然后依据不同的函数作为行为模式,进行状态转换. 有点像Finite Automata算法,两者的思想是一样的. 会Finite Automata,那么这个设计模式就非常easy了. # ...