hdu1596 find the safest road(最短路径floyd)
来源:互联网 发布:网络大电影监禁风暴 编辑:程序博客网 时间:2024/05/22 15:36
题目链接:点击打开链接
题意描述:给定一张图,给出图中每条边的权值,求任意两点之间权值之积最大?
解题思路:最短路径floyd
求权之积:通过log可以转化为求权之和
求最大:通过取加符号转化为求最小
代码:
#include <cstdio>#include <cmath>#define MAXN 1010#define eps 1e-8using namespace std;const double INF=1000010.0;double dis[MAXN][MAXN];int n,m;double fabs(double x){ if(x>=-eps) return x; return -x;}void floyd(){ for(int k=1;k<=n;++k) for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) if(dis[i][j]>dis[i][k]+dis[k][j]+eps) dis[i][j]=dis[i][k]+dis[k][j];}int main(){ double tmp; while(scanf("%d",&n)!=EOF){ for(int i=1;i<=n;++i) for(int j=1;j<=n;++j){ scanf("%lf",&tmp); if(fabs(tmp)<=eps) dis[i][j]=INF; else dis[i][j]=-log(tmp); } floyd(); int m; scanf("%d",&m); int x,y; while(m--){ scanf("%d%d",&x,&y); if(dis[x][y]>=INF-eps) printf("What a pity!\n"); else printf("%.3lf\n",exp(-dis[x][y])); } } return 0;}
0 0
- hdu1596 find the safest road(最短路径floyd)
- HDU1596 find the safest road(floyd)
- HDU find the safest road 最短路径 floyd
- HDU1596 find the safest road 最短路Floyd算法
- 杭电find the safest road(最短路径,dijkstra,floyd)
- HDU:1596 find the safest road(floyd最短路径算法+打表)
- hdu 1596 find the safest road (最短路径dijkstra SPFA Floyd)
- hdu1596 find the safest road--多源最短路径
- find the safest road hdu1596 最短路
- HDU1596 find the safest road(最短路)
- hdu 1596 find the safest road(最短路径)
- hdu1596 find the safest road(最短路)
- hdu1596 find the safest road(最短路)
- hdu1596 find the safest road
- hdu1596 find the safest road
- HDU1596---find the safest road
- hdu1596 find the safest road
- [hdu1596] find the safest road
- linux下C/C++编译时系统搜索 include 和 链接库 文件路径的指定
- Git Git命令速查 | Git命令分类 | Git常见问题
- 第二周项目1函数参数传递的三种方式
- 什么是a4j
- 关于struts2-spring整合的问题
- hdu1596 find the safest road(最短路径floyd)
- 【国际短信】功能开发经验及具体开发实现
- 生动形象的介绍数字证书及CA——保你看后必懂
- 语言中函数传参的三种方式
- C++单例模式
- 第一周项目0 初识CSDN
- JSTL分页显示 动态页码
- CSS 小总结
- POJ 2436 Disease Management