杭电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): 6380 Accepted Submission(s): 2271
可是8600 的数学不好,想请你帮忙 ^_^
第一行: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
这道题是用的floyd做的。也属于最短路中的一种方法
代码:
#include<stdio.h>
#include<string.h>
#define INF 1 << 30
double map[1001][1001] ;
void floyd(int n)
{
for(int k = 1 ; k <= n ; k++)
for(int i = 1 ; i <= n ; i++)
for(int j = 1 ; j <= n ; j++)
if(map[i][j] < map[i][k] * map[k][j])
map[i][j] = map[i][k] * map[k][j] ;
}
int main()
{
int n = 0 ;
while(~scanf("%d" , &n) && n )
{
int i = 0 , j = 0 ;
memset(map , 0 , sizeof( map ) ) ;
for( i = 1 ; i <= n ; i++)
{
for( j = 1 ; j <= n ; j++)
{
scanf("%lf",&map[i][j]);
}
}
int Q = 0 ;
scanf("%d",&Q);
floyd( n ) ;
while( Q-- && n)
{
int x , y ;
scanf("%d%d" , &x , &y);
if(map[x][y])
printf("%.3lf\n", map[x][y]) ;
else
printf("What a pity!\n") ;
}
}
return 0 ;
}
杭电1596 find the safest road的更多相关文章
- 杭电 1596 find the safest road (最短路)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 这道题目与杭电2544最短路的思想是一样的.仅仅只是是把+改成了*,输入输出有些不一样而已. find t ...
- 杭电 1596 find the safest road (最小路径变形求最大安全度)
Description XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1 间的实数(包括0,1),一条从u 到 v 的 ...
- 杭电 1595 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 (Floyd)
HDU.1596 find the safest road (Floyd) 题意分析 与普通的最短路不太相同,本题有些许的变化. 1. 要找到由i到j最安全的路,故在求解的时候要保证mp[i][j]尽 ...
- hdoj 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 (最短路径)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- find the safest road HDU杭电1596【Dijkstra || SPFA】
pid=1596">http://acm.hdu.edu.cn/showproblem.php?pid=1596 Problem Description XX星球有非常多城市,每一个城 ...
- hdoj 1596 find the safest road
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=1596 分析:Dijkstra变体,最短路径判断计算方式:Safe(P) = s(e1)*s(e2)…* ...
随机推荐
- linux入门基础——linux用户基础
这篇内容是linux用户基础,相关内容见linux改动username和ubuntu改动username和主机名. 用户.组 当我们使用linux时,须要以一个用户的身份登入,一个进程也须要以一个用户 ...
- CF 558C(Amr and Chemistry-构造法)
C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard ...
- SqlHelper——仅仅由于在人群中多看了你一眼
一.SqlHelper 出场 不是由于大家都在用SqlHelper所以才用,是由于连接数据库关闭数据库查询数据库的多了也就加上了SqlHelper.当你的非常多需求都有一个同样的方法的时候我们没有必要 ...
- CSDN高校俱乐部第二届战神杯第二题题解
两个人玩一个数字游戏,给定两个正整数A,B,两个人轮流从一个数中减去另外一个数的正数倍.要保证结果非负, 首先得到0的人获胜. 比如:30 8经过一步操作能够变为22 8 或者14 8 或者 6 8. ...
- 本地自旋锁与信号量/多服务台自旋队列-spin wait风格的信号量
周日傍晚,我去家附近的超市(...)买苏打水,准备自制青柠苏打.我感觉我做的比买的那个巴黎水要更爽口.由于天气太热,非常多人都去超市避暑去了,超市也不撵人,这仿佛是他们的策略.人过来避暑了,走的时候难 ...
- Project Euler:Problem 37 Truncatable primes
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...
- UVA 11609 - Anne's game cayley定理
Lily: “Chantarelle was part of my exotic phase.”Buffy: “It’s nice. It’s a mushroom.”Lily: “It is? Tha ...
- UESTC--1263--The Desire of Asuna(贪心)
The Desire of Asuna Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu Su ...
- FC 网络
通常情况下,SAN系统中服务器与存储介质通过一种特殊的网络相连,这种网络就是FC 网络. FC 网络是一种新发展的与传统的TCP/IP网络并列的一种高速网络.它有自己的地址分配和网络管理的体系. FC ...
- UNP学习笔记2——从一个简单的ECHO程序分析TCP客户/服务器之间的通信
1 概述 编写一个简单的ECHO(回复)程序来分析TCP客户和服务器之间的通信流程,要求如下: 客户从标准输入读入一行文本,并发送给服务器 服务器从网络输入读取这个文本,并回复给客户 客户从网络输入读 ...