HDU.1596 find the safest road (Floyd)
来源:互联网 发布:藏宝阁买号软件 编辑:程序博客网 时间:2024/06/04 19:55
HDU.1596 find the safest road (Floyd)
题意分析
与普通的最短路不太相同,本题有些许的变化。
1. 要找到由i到j最安全的路,故在求解的时候要保证mp[i][j]尽量大,而不是尽量小。
2. 当mp[i][j] = 0的时候表示无法通过,而不是为无穷大的时候无法通过。
3. 路程求解过程中,安全系数是相乘的关系,不是按照普通路径的相加的关系。
4. 此题n^3的Floyd竟然能过,我惊了。
代码总览
#include <bits/stdc++.h>#define nmax 1005using namespace std;const double eps = 1e-5;double mp[nmax][nmax];int n,m;void floyd(){ for(int k = 1; k<=n;++k){ for(int i =1 ;i<=n ;++i){ for(int j = 1; j<=n; ++j){ if(fabs(mp[i][k] - 0.0 ) <= eps || fabs(mp[k][j] - 0.0 ) <= eps ) continue; else{ double temp = mp[i][k] * mp[k][j]; if(temp > mp[i][j]){ mp[i][j] = temp; } } } } }}int main(){ while(scanf("%d",&n) !=EOF){ memset(mp,0,sizeof(mp)); for(int i = 1; i<=n ;++i){ for(int j = 1; j<=n ;++j){ scanf("%lf",&mp[i][j]); } } floyd(); scanf("%d",&m); int sta, end; for(int i = 0; i<m;++i){ scanf("%d %d",&sta,&end); double temp = mp[sta][end]; if(fabs(temp - 0.0) <=eps) printf("What a pity!\n"); else printf("%.3f\n",temp); } } return 0;}
阅读全文
0 0
- HDU 1596 find the safest road 【floyd】
- HDU 1596 find the safest road -- floyd
- HDU.1596 find the safest road (Floyd)
- hdu 1596 find the safest road (floyd)
- hdu 1596 find the safest road 最短路 FLoyd算法
- hdu 1596 find the safest road(dijkstra||floyd)
- hdu 1596 find the safest road dijkstra || floyd
- hdu 1596 floyd算法 find the safest road
- Hdu oj 1596 find the safest road(floyd)
- HDU 1596 find the safest road(水数据的 floyd)
- 1596 find the safest road【floyd】
- HDU find the safest road 最短路径 floyd
- 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
- 浅谈C/C++动态内存管理
- 5-8 哈利·波特的考试
- 微服务的一种开源实现方式——dubbo+zookeeper
- 《Android开发艺术探索》之Activity的生命周期及启动模式
- InputStream和Reader的区别
- HDU.1596 find the safest road (Floyd)
- iOS 解决iOS 地图获取位置提示框不弹出
- 对象序列化
- 文件的递归读取和递归删除
- 图像处理之模糊理论
- Mybatis入门篇(一)-框架原理
- 保存和读取 TensorFlow 模型
- Windows下一键发布Hexo静态博客
- OSGI