题目链接:http://poj.org/problem?id=2253
题目意思:Freddy Frog暗恋Fiona Frog,在他们之间有n快石头,告诉你这n快石头的坐标,第一快为Freddy Frog的坐标,第n块为Finoa Frog的坐标,Freddy可以借助石头经过任何路径到达Fiona那里,问他最小的弹跳距离是多少(即最短路径中的最长边)。
注意:该题有多组测试数据,要求每组测试数据之间空一行!
代码:
#include<stdio.h>
#include<math.h>
#include<string.h>
struct coo{
double x;
double y;
}st[205];
double map[205][205];
int flag[205];
double dis[205];
int N;
double dist(int i,int j)
{
double x1,y1;
x1=pow(st[j].x-st[i].x,2.0);
y1=pow(st[j].y-st[i].y,2.0);
return sqrt(x1+y1);
}
double max(double a,double b)
{
return a>b?a:b;
}
void dijkstra()
{
int i,j,u;
double min1;
dis[0]=0;
for(i=1;i<N;i++)
{
dis[i]=map[0][i];
flag[i]=0;
}
flag[0]=1;
for(i=1;i<N;i++)
{
min1=10000000;
for(j=1;j<N;j++)
{
if(flag[j]==0 && dis[j]<min1)
{
u=j;
min1=dis[j];
}
}
if(u==1)
break;
flag[u]=1;
{
for(j=1;j<N;j++)
{
if(flag[j]==0 && dis[j]>max(dis[u],map[u][j]))
{
dis[j]=max(dis[u],map[u][j]);
}
}
}
}
}
void main()
{
int i,j,k;
int Case=0;
while(scanf("%d",&N)!=EOF && N!=0)
{
Case++;
for(i=0;i<N;i++)
scanf("%lf%lf",&st[i].x,&st[i].y);
memset(map,0,sizeof(map));
k=0;
for(i=0;i<N;i++)
{
for(j=k;j<N;j++)
{
map[i][j]=map[j][i]=dist(i,j);
}
k++;
}
/*for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
printf("%.3lf ",map[i][j]);
printf("\n");
}*/
dijkstra();
printf("Scenario #%d\nFrog Distance = %.3lf\n\n",Case,dis[1]);
}
}
This blog explores a problem where Freddy Frog aims to find the shortest path to reach his beloved Fiona Frog by hopping on stones. Each stone's coordinates are given, and the goal is to calculate the maximum distance Freddy needs to jump to reach Fiona. The solution involves implementing Dijkstra's algorithm for finding the shortest path in a graph.

2078

被折叠的 条评论
为什么被折叠?



