find the safest road
来源:互联网 发布:反射原理java 编辑:程序博客网 时间:2024/05/30 02:26
http://acm.hdu.edu.cn/showproblem.php?pid=1596
#include<iostream>
#include<cstdio>#include<cstring>
using namespace std;
int n;
double line[1010][1010],dist[1010];
int book[1010];
int main()
{
while(cin>>n)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
scanf("%lf",&line[i][j]);
int m;
cin>>m;
int t1,t2;
while(m--)
{
memset(book,0,sizeof(book));
int k;
scanf("%d%d",&t1,&t2);
for(int i=1;i<=n;i++)
dist[i]=line[t1][i];
book[t1]=1;
for(int i=1;i<n;i++)
{
double max=-1;//这里写成了max=0结果就错了很久
for(int j=1;j<=n;j++)
if(max<dist[j] && !book[j])
{
max=dist[j];
k=j;
}
book[k]=1;
for(int j=1;j<=n;j++)
if(!book[j] && dist[j]<dist[k]*line[k][j])
dist[j]=dist[k]*line[k][j];
}
if(dist[t2]!=0)
printf("%.3f\n",dist[t2]);
else
cout<<"What a pity!"<<endl;
}
}
return 0;
}
0 0
- find the safest road
- find the safest road
- find the safest road
- find the safest road
- find the safest road
- find the safest road
- find the safest road
- find the safest road
- HDOJ find the safest road
- hdu1596 find the safest road
- hdu1596 find the safest road
- HDU1596---find the safest road
- [hdu]find the safest road
- hdu1596 find the safest road
- hdu find the safest road
- [hdu1596] find the safest road
- <hdoj1596>find the safest road
- HDU1596 find the safest road
- 设置gdb搜索目录
- innobackupex备份与xtrabackup备份对比
- (function(){$})(jQuery)的一点理解
- POJ 3687--Labeling Balls【拓扑排序 && 逆序拓扑 && 输出在拓扑排序中的位置】
- 有本事就来抓我啊~黑客平均躲藏205天
- find the safest road
- Machine Learning With Spark学习笔记(在10万电影数据上训练、使用推荐模型)
- lustre升级
- android上传文件
- css 如何元素设置水平居中
- sql 联级删除 ON DELETE CASCADE
- 【集群问题解决】Hbase的"Failed deleting my ephemeral node"错误解决
- mac上显示全部隐藏文件
- CocoaPods安装和使用教程