HDU 1596 find the safest road(SPFA)
第一行:n。n表示城市的个数n<=1000;
接着是一个n*n的矩阵表示两个城市之间的安全系数,(0可以理解为那两个城市之间没有直接的通道)
接着是Q个8600要旅游的路线,每行有两个数字,表示8600所在的城市和要去的城市
其他的输出这两个城市之间的最安全道路的安全系数,保留三位小数。
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<limits.h>
#include<queue>
using namespace std;
int n,m;
int s,e;
double a[][];
double d[];
bool vis[];
void spfa(int i)
{
queue<int>Q;
Q.push(i);
vis[i]=true;
int cur;
while(!Q.empty())
{
cur=Q.front();
Q.pop();
vis[cur]=;
int j;
for(j=;j<=n;j++)
{
if(j!=cur && a[cur][j]*d[cur]>d[j] && a[cur][j]>)
{
d[j]=a[cur][j]*d[cur];
if(!vis[j])
{
vis[j]=true;
Q.push(j);
}
}
}
}
return;
}
int main()
{
int i,j;
while(cin>>n)
{
for(i=;i<=n;i++)
for(j=;j<=n;j++)
cin>>a[i][j];
cin>>m;
while(m--)
{
cin>>s>>e;
memset(vis,false,sizeof(vis));
memset(d,,sizeof(d));
d[s]=a[s][s];
spfa(s); if(d[e]!=) printf("%.3lf\n",d[e]);
else cout<<"What a pity!"<<endl;
}
}
return ;
}
HDU 1596 find the safest road(SPFA)的更多相关文章
- HDU.1596 find the safest road (Floyd)
HDU.1596 find the safest road (Floyd) 题意分析 与普通的最短路不太相同,本题有些许的变化. 1. 要找到由i到j最安全的路,故在求解的时候要保证mp[i][j]尽 ...
- HDU 1596 find the safest road (最短路)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 1596 find the safest road (最短路径)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 1596 find the safest road
http://acm.hdu.edu.cn/showproblem.php?pid=1596 #include <cstdio> #include <cstring> #inc ...
- hdu 1596 find the safest road (变形SP && dij+heap)
Problem - 1596 变形最短路问题,给出邻接矩阵,要求求出给定点对间安全率最大值. 这题可以用dijkstra+heap来做.对于每一个查询,做一次dij即可. 代码如下: #include ...
- hdu 1596 find the safest road(最短路,模版题)
题目 这是用Dijsktra做的,稍加改动就好,1000ms..好水.. #define _CRT_SECURE_NO_WARNINGS #include<string.h> #inclu ...
- hdu 1596 find the safest road (dijkstra)
Problem Description XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1 间的实数(包括0,1),一条 ...
- 杭电 1596 find the safest road (最短路)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 这道题目与杭电2544最短路的思想是一样的.仅仅只是是把+改成了*,输入输出有些不一样而已. find t ...
- hdoj 1596 find the safest road【最短路变形,求最大安全系数】
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
随机推荐
- liunx服务器常见监控指标
1. CPU Utilization 英文翻译就是CPU的利用率75%以上就比较高了(也有说法是80%或者更高).有的博客上说除了这个指标外,还要结合Load Average和Context Swit ...
- c++ 常见问题之string
string初始化: 拷贝初始化: = 初始化变量,编译器把等号右侧的初始值拷贝到新创建的对象 string s = "stduent"; string s = s1; 直 ...
- Ubuntu 14.04—Eclipse配置Pydev
Eclipse: 1. 下载 Eclipse 最新版 访问官方网站下载 Eclipse 最新版,这个就不多说了,大家自己去下. http://www.eclipse.org/downloads/?o ...
- MVC 之下载 我的实践
Controller 1. public ActionResult DownLoad(string path,string fileName) { return File(new FileStream ...
- error: a label can only be part of a statement and a declaration is not a statement
GCC: error: a label can only be part of a statement and a declaration is not a statement switch(a){ ...
- PHP不使用递归的无限级分类
不用递归实现无限级分类,简单测试了下性能比递归稍好一点点点,但写得太复杂了,还是递归简单方便点 代码: <?php $list = array( array('id'=>1, 'pid'= ...
- PHP学习过程_Symfony_(4)_命令创建实体_以及实体关系
//项目运行php app/console server:run//创建实体php app/console doctrine:generate:entitybundle名称:实体名称例如:Symfon ...
- 编译C语言单元测试框架CUnit库的方法
引用: http://blog.csdn.net/yygydjkthh/article/details/46357421 个人备忘使用 /******************************* ...
- 支付宝AR实景红包上线不久即遭破解,官方已提高技术门槛
临近春节,阿里巴巴和腾讯的红包大战可谓下足功夫,上周支付宝推出了AR实景红包,该玩法基于"LBS+AR+红包"的方式,类似与今年火爆全球的AR手游Pekomon Go ,只不过这次 ...
- 字符串---分割成数组(str_split ),算出一个字符串中出现最多的字符, 学校中最多的姓名
split 分割separate分开 little 小的 echo '<meta http-equiv="Content-type" content="text/h ...