Problem - 1596

  变形最短路问题,给出邻接矩阵,要求求出给定点对间安全率最大值。

  这题可以用dijkstra+heap来做。对于每一个查询,做一次dij即可。

代码如下:

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue> using namespace std; const int N = ;
double wt[N][N];
bool vis[N];
#define _clr(x) memset(x, 0, sizeof(x))
typedef pair<double, int> PDBI;
priority_queue<PDBI> priq; double dij(int s, int t, int n) {
while (!priq.empty()) priq.pop();
_clr(vis);
for (int i = ; i < n; i++) priq.push(PDBI(wt[s][i], i));
while (!priq.empty()) {
double w = priq.top().first;
int id = priq.top().second;
priq.pop();
if (vis[id]) continue;
// cout << "id!!! " << id << endl;
vis[id] = true;
if (id == t) return w;
for (int i = ; i < n; i++) {
if (vis[i]) continue;
if (wt[s][i] < wt[s][id] * wt[id][i]) {
wt[s][i] = wt[s][id] * wt[id][i];
priq.push(PDBI(wt[s][i], i));
}
}
}
return wt[s][t];
} int main() {
// freopen("in", "r", stdin);
int n, m;
while (~scanf("%d", &n)) {
for (int i = ; i < n; i++) {
for (int j = ; j < n; j++) {
scanf("%lf", &wt[i][j]);
}
}
scanf("%d", &m);
for (int i = , x, y; i < m; i++) {
scanf("%d%d", &x, &y);
double ans = dij(x - , y - , n);
if (ans < 1e-) puts("What a pity!");
else printf("%.3f\n", ans);
}
}
return ;
}

——written by Lyon

hdu 1596 find the safest road (变形SP && dij+heap)的更多相关文章

  1. HDU.1596 find the safest road (Floyd)

    HDU.1596 find the safest road (Floyd) 题意分析 与普通的最短路不太相同,本题有些许的变化. 1. 要找到由i到j最安全的路,故在求解的时候要保证mp[i][j]尽 ...

  2. HDU 1596 find the safest road (最短路)

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. hdu 1596 find the safest road (最短路径)

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  4. hdu 1596 find the safest road

    http://acm.hdu.edu.cn/showproblem.php?pid=1596 #include <cstdio> #include <cstring> #inc ...

  5. hdu 1596 find the safest road(最短路,模版题)

    题目 这是用Dijsktra做的,稍加改动就好,1000ms..好水.. #define _CRT_SECURE_NO_WARNINGS #include<string.h> #inclu ...

  6. HDU 1596 find the safest road(SPFA)

    Problem Description XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1 间的实数(包括0,1),一条 ...

  7. hdu 1596 find the safest road (dijkstra)

    Problem Description XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1 间的实数(包括0,1),一条 ...

  8. hdoj 1596 find the safest road【最短路变形,求最大安全系数】

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. 杭电 1596 find the safest road (最短路)

    http://acm.hdu.edu.cn/showproblem.php?pid=1596 这道题目与杭电2544最短路的思想是一样的.仅仅只是是把+改成了*,输入输出有些不一样而已. find t ...

随机推荐

  1. ubuntu和win10设置双显示器

    ubuntu:最右上角那个图标,点开找到系统设置,系统设置中找到“显示”中,在其中可以调节双屏显示或者只显示一个屏,图等会补... win10:现在是ubuntu系统所以操作忘记了写不出来,等下换系统 ...

  2. codevs1214 线段覆盖

    1214 线段覆盖 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold       题目描述 Description 给定x轴上的N(0<N<100)条线段, ...

  3. mysql错误日志目录

    在windows下,一般是mysql安装目录下的data目录下 ,扩展名是.err的文件.

  4. python中bisect模块的使用

    一般用于二分查找, 当然列表应该是有序表 参考于: http://blog.csdn.net/xiaocaiju/article/details/6975714

  5. Spring MVC JSON自己定义类型转换

    版权声明:版权归博主全部.转载请带上本文链接.联系方式:abel533@gmail.com https://blog.csdn.net/isea533/article/details/28625071 ...

  6. 洛谷 P1073 最优贸易 最短路+SPFA算法

    目录 题面 题目链接 题目描述 输入输出格式 输入格式 输出格式 输入输出样例 输入样例 输出样例 说明 思路 AC代码 题面 题目链接 P1073 最优贸易 题目描述 C国有 $ n $ 个大城市和 ...

  7. onethink上传到服务器(或者迁移)后台登录验证码错误问题

    修改Application\User下面的配置文件config.php, 改成对应服务器上的参数 define('UC_DB_DSN', 'mysqli://root:root@127.0.0.1:3 ...

  8. LeetCode136 Single Number, LeetCode137 Single Number II, LeetCode260 Single Number III

    136. Single Number Given an array of integers, every element appears twice except for one. Find that ...

  9. Hello World 之Spring Boot 调用图数据库Neo4j

    明日歌 [清]钱鹤滩 明日复明日,明日何其多! 我生待明日,万事成蹉跎 1. 图数据库Neo4j之爱的初体验 ----与君初相识,犹似故人归 在如今大数据(big data)横行的时代,传统的关系型数 ...

  10. nginx简单使用

    nginx开启./nginx重启./nginx -s reload关闭./nginx -s stop或quit