hdoj 1596 find the safest road【最短路变形,求最大安全系数】
find the safest road
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9122 Accepted Submission(s):
3213
0 和 1 间的实数(包括0,1),一条从u 到 v 的通道P 的安全度为Safe(P) = s(e1)*s(e2)…*s(ek) e1,e2,ek是P 上的边
,现在8600 想出去旅游,面对这这么多的路,他想找一条最安全的路。但是8600 的数学不好,想请你帮忙 ^_^
第一行:n。n表示城市的个数n<=1000;
接着是一个n*n的矩阵表示两个城市之间的安全系数,(0可以理解为那两个城市之间没有直接的通道)
接着是Q个8600要旅游的路线,每行有两个数字,表示8600所在的城市和要去的城市
pity!",
其他的输出这两个城市之间的最安全道路的安全系数,保留三位小数。
#include<stdio.h>
#include<string.h>
#define MAX 1010
#define INF 0x3f3f3f
#define DD double
int n,m;
DD map[MAX][MAX],low[MAX];
int vis[MAX];
void getmap()
{
int i,j;
DD a;
memset(map,0,sizeof(map));
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%lf",&a);
map[i][j]=a;
}
}
}
void dijkstra(int a,int b)
{
int i,j,next;
DD max;
for(i=1;i<=n;i++)
low[i]=map[a][i];
memset(vis,0,sizeof(vis));
vis[a]=1;
for(i=1;i<n;i++)
{
max=0;
next=a;
for(j=1;j<=n;j++)
{
if(!vis[j]&&max<low[j])
{
next=j;
max=low[j];
}
}
vis[next]=1;
for(j=1;j<=n;j++)
{
if(!vis[j]&&low[j]<low[next]*map[next][j]) //此处的求法有所不同
low[j]=low[next]*map[next][j];
}
}
if(low[b]==0)
printf("What a pity!\n");
else
printf("%.3lf\n",low[b]);
}
void solve()
{
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
int a,b;
scanf("%d%d",&a,&b);
if(a==b)
printf("1.000\n");//注意自己到自己的情况
else
dijkstra(a,b);
}
}
int main()
{
int i,j;
while(scanf("%d",&n)!=EOF)
{
getmap();
solve();
}
return 0;
}
hdoj 1596 find the safest road【最短路变形,求最大安全系数】的更多相关文章
- HDU 1596 find the safest road (最短路)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdoj 1596 find the safest road
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=1596 分析:Dijkstra变体,最短路径判断计算方式:Safe(P) = s(e1)*s(e2)…* ...
- hdu 1596 find the safest road(最短路,模版题)
题目 这是用Dijsktra做的,稍加改动就好,1000ms..好水.. #define _CRT_SECURE_NO_WARNINGS #include<string.h> #inclu ...
- HDU.1596 find the safest road (Floyd)
HDU.1596 find the safest road (Floyd) 题意分析 与普通的最短路不太相同,本题有些许的变化. 1. 要找到由i到j最安全的路,故在求解的时候要保证mp[i][j]尽 ...
- 杭电 1596 find the safest road (最短路)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 这道题目与杭电2544最短路的思想是一样的.仅仅只是是把+改成了*,输入输出有些不一样而已. find t ...
- 杭电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 ...
随机推荐
- iOS中判断消息推送是否打开
根据 [[UIApplication sharedApplication] enabledRemoteNotificationTypes] 的返回值来进行判断,该返回值是一个枚举值,如下: typed ...
- 彻底删除sql2008r2
一. SQL2008卸载. 1.从控制面板卸载 1)点击计算机右下角“开始”,点击“控制面板” 2)点击“卸载程序”. 3)在程序列表中找到“Microsoft SQL Server 2008” ...
- 开启 htaccess 配置
是在wamp中,apache2.2 开启 伪静态时,httpd.conf 配置如下: 查找 <Directory />Options FollowSymLinksAllowOverride ...
- Git新手入门手册
1.配置email及name git config --global user.email "guxuelong@f-road.com.cn" git config --globa ...
- <string> <string.h>
在C++开发过程中经常会遇到两个比较容易混淆的头文件引用#include<string.h> 和 #include<string>,两者的主要区别如下: #include< ...
- Application_Start
这个时间是在第一次访问网站的时候触发..比如你发布了一个网站,,我第一个来访问,,就会触发这个事件..以后再有人来访问就不会触发了.. 一般的,我们总是以为Application_Start是一个应用 ...
- 使用pyinstaller 2.1将python打包并添加版本信息和图标
最近用 wxpython写了一个小的脚本,因为想要发布给没有装python和wxpython的人使用,遂决定使用pyinstaller 2.1进行打包. 其中遇到几个问题: 1,给打包的文件添加图标 ...
- 简单安装python的pip工具模块
下载最新pip安装包 https://pypi.python.org/pypi/pip#downloads 安装 .tar.gz cd pip-.tar.gz python setup.py inst ...
- iOS: 学习笔记, 添加一个带界面约束的控制器
1. 创建一个空iOS应用程序(Empty Application). 2. 添加加控制器类. 修改控制器类的viewDidLoad - (void)viewDidLoad { [super view ...
- WPFDispatcher示例
Dispatcher 类提供用于管理线程工作项队列的服务. 效果演示: <Window x:Class="WPF之Dispatcher对象.MainWindow" xmlns ...