HDU 1596 最短路变形
这道题怎么都是TLE,报警了,先放在这
http://acm.hdu.edu.cn/showproblem.php?pid=1596
#include <iostream>
#include <iomanip>
using namespace std; #define MAXVEX 1001 double matrix[MAXVEX][MAXVEX];
double D[MAXVEX]; int n; void Dijkstral(int v0)
{
int v,w,k=;
double max;
int final[MAXVEX]; for(int i = ;i<=n;i++)
{
D[i] = matrix[v0][i];
final[i] = ;
} final[v0] = ; for(v=;v<=n;v++)
{
max = -;
for(w=;w<=n;w++)
{
if(D[w]>max && !final[w])
{
max = D[w];
k = w;
}
} final[k] = ; for(w=;w<=n;w++)
{
if(max*matrix[k][w]>D[w] && !final[w])
{
D[w]=max*matrix[v][w];
}
}
} } int main()
{
while(cin>>n)
{
for(int i = ;i<=n;i++)
{
for(int j = ;j<=n;j++)
cin>>matrix[i][j];
} int m;
cin>>m;
while(m--)
{
int a,b;
cin>>a>>b; Dijkstral(a); if(D[b])
cout<<fixed<<setprecision()<<D[b]<<endl;
else
cout<<"What a pity!\n";
}
}
return ;
}
ac了,1482MS
#include <cstdio>
using namespace std;
const int L = ;
const int INF = <<; double map[L][L];
int vis[L];
double dis[L]; int n,m; void Dijkstra(int s)
{
int i,j,k;
double max;
for(i = ;i<=n;i++)
{
dis[i] = map[s][i];
vis[i] = ;
} vis[s] = ;
dis[s] = ; for(i = ;i<=n;i++)
{
max = ;
for(j = ;j<=n;j++)
{
if(dis[j]>max && !vis[j])
{
k = j;
max = dis[j];
}
} vis[k] = ; for(j = ;j<=n;j++)
{
if(dis[j] < max*map[k][j] && !vis[j])
{
dis[j] = max*map[k][j];
}
}
}
} void init()
{
int i,j;
for(i = ;i<=n;i++)
{ for(j = ;j<=n;j++)
{
scanf("%lf",&map[i][j]);
}
}
} int main()
{
while(scanf("%d",&n)!=EOF)
{
int r,t; init(); scanf("%d",&r);
while(r--)
{
int a,b;
scanf("%d%d",&a,&b);
Dijkstra(a);
if(dis[b])
printf("%.3lf\n",dis[b]);
else
printf("What a pity!\n");
} } return ;
}
HDU 1596 最短路变形的更多相关文章
- hdu 1596(Floyd 变形)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...
- hdu 3986(最短路变形好题)
Harry Potter and the Final Battle Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/6553 ...
- hdu 1595(最短路变形好题)
find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others) Memory Limit: 32768/32768 ...
- HDOJ find the safest road 1596【最短路变形】
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 1596 find the safest road (变形SP && dij+heap)
Problem - 1596 变形最短路问题,给出邻接矩阵,要求求出给定点对间安全率最大值. 这题可以用dijkstra+heap来做.对于每一个查询,做一次dij即可. 代码如下: #include ...
- 最短路变形题目 HDU多校7
Mr.Quin love fishes so much and Mr.Quin’s city has a nautical system,consisiting of N ports and M sh ...
- HDU.1596 find the safest road (Floyd)
HDU.1596 find the safest road (Floyd) 题意分析 与普通的最短路不太相同,本题有些许的变化. 1. 要找到由i到j最安全的路,故在求解的时候要保证mp[i][j]尽 ...
- ACM: HDU 2544 最短路-Dijkstra算法
HDU 2544最短路 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descrip ...
- UESTC 30 &&HDU 2544最短路【Floyd求解裸题】
最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- 《快学Scala》第三章 数组相关操作
- CentOS7系统安装 Maria Db(MYSQL)教程
一.背景Maria Db是流行的跨平台MySQL数据库管理系统的分支,被认为是MySQL 的完全替代品.Maria Db是由Sun在Sun Micro systems合并期间被Oracle收购后,于2 ...
- CodeForces - 556C-Case of Matryoshkas(思维)
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at ...
- Go语言容器
Map 是一种无序的键值对的集合.Map 最重要的一点是通过 key 来快速检索数据,key 类似于索引,指向数据的值. Map 是一种集合,所以我们可以像迭代数组和切片那样迭代它.不过,Map 是无 ...
- P2486 [SDOI2011]染色(树剖)区间覆盖+区间的连续段
https://www.luogu.org/problemnew/show/P2486 值的一看https://www.cnblogs.com/Tony-Double-Sky/p/9283262.ht ...
- 关于MatlabGUI清除WorkSpace的用法
近日在调试Matlba GUI程序时,因为不想退出程序后手动Clear All来清理,又需要在过程中对WorkSpace进行清理,否则会引用之前的结果导致错误,找了很多资料,国内的论坛什么的都说用Cl ...
- 微信小程序授权流程(图)
看图: 1. 前端H5调用JSSKD的方法 wx.login(), 2. 微信返回 临时登录凭证code 给前端H5 3. 将此Code给到开发者服务器 4. 服务器混同小程序的AppId 和 Ap ...
- (转)Python 字符串格式化 str.format 简介
原文:https://www.cnblogs.com/wilber2013/p/4641616.html http://blog.konghy.cn/2016/11/25/python-str-for ...
- deepin安装php5.6
sudo su -echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu xenial main" | tee -a /etc/a ...
- yaf视图
Yaf默认是开启了自动渲染,所以建了action后,他就会自己找模板!在测试的时候,如果不想让他寻找模板可以在action中return false 或者在bootstrap.php中关闭渲染 Yaf ...