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. tomcat标准化安装

    操作系统说明: 操作系统 版本 linux red hat release 6.4 关键软件包说明: 软件包 版本 目录 运行用户 jdk-7u79-linux-x64.gz 1.7 /usr/loc ...

  2. 【Codeforces Round #430 (Div. 2) D】Vitya and Strange Lesson

    [链接]点击打开链接 [题意] 给出一个数组,每次操作将整个数组亦或一个数x,问得到的数组的结果中的mex.mex表示为自然数中第一个没有出现过的数. [题解] 异或的效果是可以累加的,所以不用每次都 ...

  3. java如何访问memcache

    1       Memcache是什么 Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的,目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的 ...

  4. 笔试面试记录-字符串转换成整型数等(aatoi,itoa)

    C语言中经常用到字符串与数字之间的相互转换,常见的此类库函数有atof(字符串转换成浮点数).atoi(字符串转换成整型数).atol(字符串转换成长整形).itoa(整型数转换成字符串).ltoa( ...

  5. Python之collection

    1.计数器(counter) Counter是对字典类型的补充,用于追踪值的出现次数. ps:具备字典的所有功能 + 自己的功能 c = Counter('abcdeabcdabcaba') prin ...

  6. $.inArray()方法

    $.inArray() 函数用于在数组中查找指定值,并返回它的索引值(如果没有找到,则返回-1) 提示:源数组不会受到影响,过滤结果只反映在返回的结果数组中. 语法 $.inArray( value, ...

  7. SDUT-3363_驴友计划

    数据结构实验之图论七:驴友计划 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 做为一个资深驴友,小新有一张珍藏的自驾游 ...

  8. Person Re-identification 系列论文笔记(六):AlignedReID

    AlignedReID Zhang X, Luo H, Fan X, et al. AlignedReID: Surpassing Human-Level Performance in Person ...

  9. c++编译错误:invalid new-expression of abstract class type

    原因: 出现这个错误原因是new 了一个抽象类出错,说明父类(接口)中有纯虚函数没有实现.接口里的纯虚函数全部需要实现,这样才能new 子类. 例如: 纯虚函数例如 ; 是纯虚函数,不是纯虚函数不作要 ...

  10. 将nginx搜集到的日志通过flume转到hive

    背景介绍: Nginx为app打点数据,打点日志每小时滚动一次.目录结构如下 文件中的数据如下( cat -A 2019072414r.log 后的结果,-A为显示隐形的符号,下方^A为指定的分隔符. ...