find the safest road hd 1596
来源:互联网 发布:淘宝客服服务流程 编辑:程序博客网 时间:2024/06/16 17:07
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
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<cstdio>#include<cstring>#include<algorithm>using namespace std;double pri[1100][1100];int a;int max(int x,int y){if(x>y)return x;return y;}void floyd(){for(int k=1;k<=a;k++){for(int i=1;i<=a;i++){for(int j=1;j<=a;j++){if(pri[i][k]!=0&&pri[k][j]!=0)pri[i][j]=max(pri[i][j],pri[i][k]*pri[k][j]);}}}}int main(){int i,j,b,n,m;while(scanf("%d",&a)!=EOF){for(i=1;i<=a;i++){for(j=1;j<=a;j++){scanf("%lf",&pri[i][j]);}}floyd();scanf("%d",&b);while(b--){scanf("%d%d",&n,&m);if(pri[n][m]==0)printf("What a pity!\n");else printf("%.3lf\n",pri[n][m]);}}return 0;}
0 0
- find the safest road hd 1596
- HD--1596 find the safest road
- 【HD 1596】find the safest road
- find the safest road
- find the safest road
- find the safest road
- find the safest road
- find the safest road
- find the safest road
- find the safest road
- find the safest road
- hdu 1596 find the safest road(priority_queue )
- HDU 1596 find the safest road
- HDU-1596 find the safest road
- hdu 1596 find the safest road
- hdu 1596 find the safest road
- HDU-1596-find the safest road
- HDU 1596 find the safest road
- 互点宝SEO软件官方版
- hdu 5783 Divide the Sequence
- 手机端网页处理手机返回键
- intelli IDEA j安装scala插件
- BaseFragment的抽取
- find the safest road hd 1596
- Windows平台编译libevent
- POJ1112——Team Them Up!(动态规划,二分图判定)
- css定义table表格边框技巧分享
- C/C++传入数组及怎样限定传入数组的大小
- PCL中std::numeric_limits::max()编译错误
- 一步步将vim改造成C/C++开发环境(IDE)
- 推荐系统的相关算法SVD
- 深入浅出spring IOC中三种依赖注入方式