POJ - 2253 - Frogger = Dijkstra
http://poj.org/problem?id=2253
题意:给一些点,完全图,边权是欧几里得距离,最小化从1号点到2号点的路径中的最大边权。
显然的Dijkstra乱搞题,以前还有用Prim改的,虽然Prim和Dijkstra是一个东西。
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
double G[205][205];
double dis[205];
bool vis[205];
priority_queue<pair<double, int> > pq;
void dijkstra(int s, int n) {
while(!pq.empty())
pq.pop();
for(int i = 1; i <= n; ++i) {
dis[i] = 1e18;
vis[i] = 0;
}
dis[s] = 0;
pq.push({-dis[s], s});
while(!pq.empty()) {
int u = pq.top().second;
pq.pop();
if(vis[u])
continue;
vis[u] = 1;
for(int v = 1; v <= n; ++v) {
double w = G[u][v];
if(!vis[v] && dis[v] > max(dis[u], w)) {
dis[v] = max(dis[u], w);
pq.push({-dis[v], v});
}
}
}
}
double x[205], y[205];
int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
#endif // Yinku
int n, sc = 0;
while(~scanf("%d", &n)) {
if(n == 0)
break;
for(int i = 1; i <= n; ++i) {
scanf("%lf%lf", &x[i], &y[i]);
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
G[i][j] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
}
}
dijkstra(1, n);
printf("Scenario #%d\n", ++sc);
printf("Frog Distance = %.3f\n\n", dis[2]);
}
}