hdu 1596 find the safest road (dijkstra)
第一行:n。n表示城市的个数n<=1000;
接着是一个n*n的矩阵表示两个城市之间的安全系数,(0可以理解为那两个城市之间没有直接的通道)
接着是Q个8600要旅游的路线,每行有两个数字,表示8600所在的城市和要去的城市
其他的输出这两个城市之间的最安全道路的安全系数,保留三位小数。
3
1 0.5 0.5
0.5 1 0.4
0.5 0.4 1
3
1 2
2 3
1 3
0.500
0.400
0.500
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; const long long INF=1e9+7;
const int maxn=1010; int n,m,st,ed;
double tu[maxn][maxn],degeree[maxn];
int vis[maxn]; void dijkstra(int st,int ed)
{
int i,j;
for(i=1; i<=n; i++)
{
degeree[i]=tu[st][i];
vis[i]=0;
}
vis[st]=1;
bool flag=0;
double maxx;
for(i=1; i<n; i++)
{
int k;
maxx=0;
for(j=1; j<=n; j++)
{
if(!vis[j]&°eree[j]>maxx)
{
k=j;
maxx=degeree[j];
}
}
if(fabs(maxx)<10e-6)
{
flag=1;
break;
}
vis[k]=1;
for(j=1; j<=n; j++)
{
if(!vis[j]&&tu[k][j]>0&°eree[j]<tu[k][j]*degeree[k])
{
degeree[j]=degeree[k]*tu[k][j];
}
}
}
if(flag) printf("What a pity!\n");
else printf("%.3lf\n",degeree[ed]);
} int main()
{
int i,j;
while(~scanf("%d",&n))
{
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
scanf("%lf",&tu[i][j]);
scanf("%d",&m);
while(m--)
{
scanf("%d %d",&st,&ed);
dijkstra(st,ed);
}
}
return 0;
}
hdu 1596 find the safest road (dijkstra)的更多相关文章
- hdu 1596 find the safest road (变形SP && dij+heap)
Problem - 1596 变形最短路问题,给出邻接矩阵,要求求出给定点对间安全率最大值. 这题可以用dijkstra+heap来做.对于每一个查询,做一次dij即可. 代码如下: #include ...
- 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 ...
- 杭电 1596 find the safest road (最短路)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 这道题目与杭电2544最短路的思想是一样的.仅仅只是是把+改成了*,输入输出有些不一样而已. find t ...
- 杭电1596find the safest road(spfa)
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(最短路,模版题)
题目 这是用Dijsktra做的,稍加改动就好,1000ms..好水.. #define _CRT_SECURE_NO_WARNINGS #include<string.h> #inclu ...
- HDU 1596 find the safest road(SPFA)
Problem Description XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1 间的实数(包括0,1),一条 ...
随机推荐
- fastreport中文乱码问题
fastreport的中文乱码问题,确实让人头疼,我使用的是delphi6+fastrepport4.7,在4.7版本中,主要表现在以下几种情况. 预览不乱码,保存乱码. 简体不乱码,繁体乱码. 简体 ...
- (三)配置Hadoop1.2.1+eclipse(Juno版)开发环境,并运行WordCount程序
配置Hadoop1.2.1+eclipse(Juno版)开发环境,并运行WordCount程序 一. 需求部分 在ubuntu上用Eclipse IDE进行hadoop相关的开发,需要在Eclip ...
- array_unshift() 函数
出处:http://www.w3school.com.cn/php/func_array_unshift.asp
- 2018中国科大自主测试-B卷部分试题
数学部分 z = e^{\frac{2i\pi}{3}}, 求z^{2018}. \sin(2x) = \frac 35, 求\frac{\tan(x+15^{\circ})}{\tan(x-15^{ ...
- shell source命令说明
当我修改了/etc/profile文件,我想让它立刻生效,而不用重新登录:这时就想到用source命令,如:source /etc/profile对source进行了学习,并且用它与sh 执行脚本进行 ...
- HttpURLConnection传json
private static String sendToWangTing(DataRow dataRow) throws IOException{ String ip = Configuration. ...
- 85.Maximal Rectangle---dp
题目链接:https://leetcode.com/problems/maximal-rectangle/description/ 题目大意:给出一个二维矩阵,计算最大的矩形面积(矩形由1组成).例子 ...
- java各种链路工具性能监控工具
Zipkin , Instana 和 Jaeger cat链路追踪系统 用于监控spring 的运行情况,比如内存,线程,池等宏观数据 spring boot admin java反编译 jar xv ...
- Mysql 中 char 、varchar 、text的区别
首先它们的存储方式和数据的检索方式都不一样.数据的检索效率是:char > varchar > text 空间占用方面,就要具体情况具体分析了. char:存储定长数据很方便,CHAR字段 ...
- 企业级-Mysql双主互备高可用负载均衡架构(基于GTID主从复制模式)(原创)
前言: 原理与思想 这里选用GTID主从复制模式Mysql主从复制模式,是为了更加确保主从复制的正确性.健康性与易配性.这里做的是两服务器A,B各有Mysql实例331 ...