求从a[1]跳到a[2](可直接1->2, 也可1->3->6->.......->2)
的所有路径为s1,s2,s3.....
t[i]为路径s[i]中跳的最长的一步
求所有t[i]中最小的t[k]
的所有路径为s1,s2,s3.....
t[i]为路径s[i]中跳的最长的一步
求所有t[i]中最小的t[k]
Dijkstra()算法变形即可
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define M 205
double maxd[M][M];
struct Node
{
double x,y;
}a[M];
int n;
double dis(Node a,Node b)
{
return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
}
void read()
{
int i,j;
for(i=1;i<=n;i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
maxd[i][j]=dis(a[i],a[j]);
}
}
}
void cal()
{
int i,j,k;
while(true)
{
bool bans=false;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
for(k=1;k<=n;k++)
{
if(maxd[i][k]>max(maxd[i][j],maxd[j][k]))
{
maxd[i][k]=max(maxd[i][j],maxd[j][k]);
bans=true;
}
}
}
}
if(!bans)
{
break;
}
}
}
void answer(int num)
{
printf("Scenario #%d\nFrog Distance = %.3lf\n\n",num,maxd[1][2]);
}
int main()
{
int id=0;
while(~scanf("%d",&n),n)
{
read();
cal();
answer(++id);
}
}
594

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



