find the safest road
来源:互联网 发布:淘宝卖家商品管理软件 编辑:程序博客网 时间:2024/05/16 09:34
XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1 间的实数(包括0,1),一条从u 到 v 的通道P 的安全度为Safe(P) = s(e1)*s(e2)…*s(ek) e1,e2,ek是P 上的边 ,现在8600 想出去旅游,面对这这么多的路,他想找一条最安全的路。但是8600 的数学不好,想请你帮忙 ^_^
第一行:n。n表示城市的个数n<=1000;
接着是一个n*n的矩阵表示两个城市之间的安全系数,(0可以理解为那两个城市之间没有直接的通道)
接着是Q个8600要旅游的路线,每行有两个数字,表示8600所在的城市和要去的城市
其他的输出这两个城市之间的最安全道路的安全系数,保留三位小数。
31 0.5 0.50.5 1 0.40.5 0.4 131 22 31 3
0.5000.4000.500
题意:中文题目就不说了;
多个起点终点,数据不大,可以用floyd求任意两点的最短距离;
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>#include<queue>using namespace std;const int MAXN=1000+10;const double inf=100000.0;int n;double map[MAXN][MAXN],dis[MAXN];int book[MAXN];int main(){ while(~scanf("%d",&n)) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { scanf("%lf",&map[i][j]); } } for(int k=1;k<=n;k++) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { map[i][j]=max(map[i][j],map[i][k]*map[k][j]); } } } int m,a,b; scanf("%d",&m); for(int i=1;i<=m;i++) { scanf("%d%d",&a,&b); if(map[a][b]) printf("%.3lf\n",map[a][b]); else printf("What a pity!\n"); } } return 0;}
阅读全文
0 0
- 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
- HDOJ find the safest road
- hdu1596 find the safest road
- hdu1596 find the safest road
- HDU1596---find the safest road
- [hdu]find the safest road
- hdu1596 find the safest road
- hdu find the safest road
- [hdu1596] find the safest road
- <hdoj1596>find the safest road
- HDU1596 find the safest road
- class object trait 区别
- 微信小程序之多行文本省略号
- Java IO操作——数据操作流DataOutputStream和DataInputStream的使用
- 说话到演讲
- js面向对象之this指向
- find the safest road
- _xchg的用法
- 对象的归档/解挡
- js和jquery获取元素的方法
- freeRTOS计算任务堆栈使用情况:
- HDU-2064:汉诺塔III
- 【概率证明】—— sum and product rules of probability
- Java中调度线程池ScheduledThreadPoolExecutor原理探究
- Python入门系列——第3篇