POJ 2253 Difference of Clustering

时间:2021-08-30 19:39:46

题意:给出一堆点,求从起点到终点的所有通路中相邻点的距离的最大值的最小值。(意思就是自己百度吧……)

解法:用相邻点的最大值作为权值代替路径的距离跑最短路或者最小生成树。然后我写了一个我以为是优化过的dijkstra但好像是prim的东西- -啊差不多啦……

总之用优先队列维护权值进行广搜……然后交G++一直wa也不知道为啥……交了C++就过了……

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
struct node
{
int x, y;
}p[205];
struct node1
{
int point;
int step;
node1(int point, int step) : point(point), step(step) {}
node1() {}
bool operator < (const node1 &tmp) const
{
return step > tmp.step;
}
};
int n;
int caldis(node a, node b)
{
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
int dis[205][205];
vector <int> edge[205];
bool vis[205];
double bfs()
{
memset(vis, 0, sizeof vis);
priority_queue <node1> q;
q.push(node1(0, 0.0));
while(!q.empty())
{
node1 tmp = q.top();
q.pop();
vis[tmp.point] = 1;
if(tmp.point == 1) return tmp.step;
for(int i = 0; i < edge[tmp.point].size(); i++)
{
if(!vis[edge[tmp.point][i]]) q.push(node1(edge[tmp.point][i], max(tmp.step, dis[tmp.point][edge[tmp.point][i]])));
}
}
}
int main()
{
int cse = 1;
while(~scanf("%d", &n) && n)
{
for(int i = 0; i < n; i++)
scanf("%d%d", &p[i].x, &p[i].y);
int maxn = 0.0;
for(int i = 0; i < n; i++)
edge[i].clear();
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
{
if(i == j) continue;
int tmp = caldis(p[i], p[j]);
edge[i].push_back(j);
dis[i][j] = tmp;
}
double ans = bfs();
printf("Scenario #%d\nFrog Distance = %.3lf\n\n", cse++, sqrt(ans));
}
return 0;
}