POJ【2253】Frogger(最小最大值)
作者:互联网
题目链接:http://poj.org/problem?id=2253
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
const int N = 200 + 10;
int n;
double a[N][N],d[N],inq[N];
struct Stone {
int x,y;
} s[N];
void SPFA(int s)
{
for(int i = 0; i < n; i++) {
d[i] = INF;
inq[i] = 0;
}
d[s] = 0;//从起点到终点的路径中某一权值最小的边
queue<int> q;
q.push(s);
while(!q.empty()) {
int u = q.front();q.pop();
inq[u] = 0;
for(int v = 0; v < n; v++)
if(d[v] > max(d[u],a[u][v])) {//修改松弛操作
//d[v] = min(d[v],max(d[u],a[u][v]));
d[v] = max(d[u],a[u][v]);
if(!inq[v]) {
inq[v] = 1;
q.push(v);
}
}
}
}
double calc(Stone s1,Stone s2)
{
return sqrt(1.0 * (s1.x - s2.x) * (s1.x - s2.x) + 1.0 * (s1.y - s2.y) * (s1.y - s2.y));
}
int main()
{
int k = 0;
while(scanf("%d",&n) && n) {
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
a[i][j] = INF;
for(int i = 0; i < n; i++)
scanf("%d%d",&s[i].x,&s[i].y);
for(int i = 0; i < n; i++)
for(int j = i + 1; j < n; j++)
a[i][j] = a[j][i] = calc(s[i],s[j]);
SPFA(0);
if(k++) printf("\n");
printf("Scenario #%d\n",k);
printf("Frog Distance = %.3f\n",d[1]);//注意printf不要使用lf
}
return 0;
}
标签:int,s2,s1,inq,++,POJ,include,2253,Frogger 来源: https://blog.csdn.net/qq_43498798/article/details/100109303