最短路-find the safest road
来源:互联网 发布:安卓新闻客户端源码 编辑:程序博客网 时间:2024/05/17 20:31
#include<stdio.h>
double map[1005][1005];
double a[1005];
int v[1005];
int main()
{
int n,m;
while(scanf("%d",&n)!=EOF)
{
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
scanf("%lf",&map[i][j]);
if(i==j)
map[i][j]=1;
}
}
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];
}
}
}
}
/*for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
printf("%.4f ",map[i][j]);
printf("\n");
}*/
scanf("%d",&m);
while(m--)
{
int x,y;
scanf("%d%d",&x,&y);
if(map[x][y]==0)
printf("What a pity!\n");
else
printf("%.3f\n",map[x][y]);
}
}
return 0;
}
/*
3
1 0.5 0.5
0.5 1 0.4
0.5 0.4 1
3
1 2
2 3
1 3
*/
double map[1005][1005];
double a[1005];
int v[1005];
int main()
{
int n,m;
while(scanf("%d",&n)!=EOF)
{
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
scanf("%lf",&map[i][j]);
if(i==j)
map[i][j]=1;
}
}
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];
}
}
}
}
/*for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
printf("%.4f ",map[i][j]);
printf("\n");
}*/
scanf("%d",&m);
while(m--)
{
int x,y;
scanf("%d%d",&x,&y);
if(map[x][y]==0)
printf("What a pity!\n");
else
printf("%.3f\n",map[x][y]);
}
}
return 0;
}
/*
3
1 0.5 0.5
0.5 1 0.4
0.5 0.4 1
3
1 2
2 3
1 3
*/
- find the safest road(floyd最短路)
- 最短路-find the safest road
- find the safest road hdu1596 最短路
- HDU1596 find the safest road(最短路)
- 【最短路+dijkstra+floyd+spfa】1596 find the safest road
- hdu1596 find the safest road 最短路dijkstra
- hdu1596 find the safest road 最短路也能求最大值
- hdu 1596 find the safest road (最短路)
- HDU 1596 find the safest road 最短路求最大值
- HDOJ--1596--find the safest road【最短路】
- hdu1596 find the safest road(最短路)
- HDU 1596find the safest road(最短路变形)
- hdu 1596 find the safest road(乘积最短路)
- HDU-1596-find the safest road(最短路)
- HDU 1596 find the safest road (最短路)
- 杭电 1596 find the safest road (最短路)
- HDU1596 find the safest road 最短路Floyd算法
- hdu 1596 find the safest road 最短路 FLoyd算法
- QT网络编程-http
- 通过magento后台的magento connect安装magento extension
- QT网络编程-UDP
- 基于数组的循环队列
- shell脚本:一次读取文件的一行【转】
- 最短路-find the safest road
- 简易的c垃圾收集器
- Ubuntu修改更新源
- 青灰色年华(21-27)
- log4j配置详解
- HBase入门5(集群) -压力分载与失效转发
- Hama学习笔记(3)-编写BSP程序
- ASP.NET中生成PDF文件
- 统计文件中某个单词出现的次数