# POJ 2253 Frogger （最短路）

### 代码部分


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <string>
#include <math.h>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3
const int N = 205;
double dis[N];   ///存储最短路
int vis[N];  ///记录是否在队列
int n;
double w[N][N];  ///两点间的距离
struct poin
{
int x,y;
}po[N];  ///点
void init()  ///初始化
{
for (int i = 0;i <= n; i++)
{
dis[i] = inf;
vis[i] = 0;
}
}
double Width(poin x,poin y) ///两点距离
{
double w;
w = sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));
return w;
}
void spfa()
{
queue<int>q;
q.push(1);
vis[1] = 1;
dis[1] = 0;
while (!q.empty())
{
int t = q.front();
q.pop();
for (int i = 1; i <= n; i++)
{
if (dis[i] > max(dis[t],w[t][i]))  ///松弛
{
dis[i] = max(dis[t],w[t][i]);
if (!vis[i])   ///判断是否在队列
{
q.push(i);
vis[i] = 1;
}
}
}
vis[t] = 0;
}
}
int main()
{
int cas = 1;
while (scanf("%d",&n),n)
{
init();
for(int i =1; i <= n;i++)
{
double s;
scanf("%d %d",&po[i].x,&po[i].y);
for (int j= 1 ;j <= i; j++)  ///处理坐标边距离
{
s = Width(po[i],po[j]);
w[i][j] = s;
w[j][i] = s;
}
}
spfa();
printf("Scenario #%d\n",cas++);
printf("Frog Distance = %.3f\n\n",dis[2]);
}
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120