HDU - 1596 find the safest road (最短路水题)
来源:互联网 发布:马斯达城 知乎 编辑:程序博客网 时间:2024/06/06 18:02
题目大意:找出两点见安全系数最高的那条路
解题思路:直接最短路解决
#include <cstdio>#include <cstring>#include <cmath>#include <queue>#define INF 0x3f3f3f3f#define N 1010#define M 1000010#define esp 1e-8using namespace std;struct Node { int to, next; double len;}node[M];int n, m, cnt, s, e, head[N];bool vis[N];double d[N], dis[N][N];void init() { double x; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { scanf("%lf", &dis[i][j]); }}bool dij() { bool flag = false;; for (int i = 1; i <= n; i++) { d[i] = 0.0; vis[i] = false; } d[s] = 1.0; for (int i = 1; i <= n - 1; i++) { int x; double tmp = 0.0; for (int j = 1; j <= n; j++) { if (!vis[j] && d[j] - tmp > esp) { tmp = d[j]; x = j; } } if (x == e) return true; vis[x] = true; for (int j = 1; j <= n; j++) { if (!vis[j] && d[x] * dis[x][j] - d[j] > esp) { d[j] = d[x] * dis[x][j]; if (j == e) flag = true; } } } return flag;} void solve() { scanf("%d", &m); int x, y; for (int i = 0; i < m; i++) { scanf("%d%d", &s, &e); if (!dij()) printf("What a pity!\n"); else printf("%.3lf\n", d[e]); }}int main() { while (scanf("%d", &n) != EOF) { init(); solve(); } return 0;}
0 0
- HDU 1596find the safest road(最短路变形)
- HDU-1596 find the safest road(最短路[Dijkstra])
- HDU 1596 find the safest road (最短路)
- HDU - 1596 find the safest road (最短路水题)
- 两道最短路裸题(HDU 2544 最短路 / 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 (最短路)
- hdu 1596 find the safest road 最短路 FLoyd算法
- HDU 1596 find the safest road(最短路变形)
- HDU Problem 1596 find the safest road【最短路dijkstra】
- 【HDU】-find the safest road(最短路)(dijkstra)
- 杭电 1596 find the safest road (最短路)
- HDOJ 1596 find the safest road(floyd最短路)
- HDOJ 1596 find the safest road(最短路)
- HDU 1596(find the safest road) 最短路(SPFA&FLOYD&Dijkstra)
- ReferenceError: Invalid assignment left-hand side
- nyoj106 背包问题
- 黑马程序员----java基础String和stringbuffer总结
- 1026. Table Tennis (30)
- HDU - 4034 Graph (floyd变形)
- HDU - 1596 find the safest road (最短路水题)
- 成功将qt程序移植到arm板上
- nyoj12 喷水装置(二)
- 组合模式
- java jdk TimSort
- 私有继承与保护继承
- Web单元测试常用工具介绍
- JSP
- HDU 2199 --Can you solve this equation?【二分水题】