Test instructions: Gives a pile of points, the minimum value of the maximum distance from the point of origin to the end of all paths. (The meaning is oneself Baidu bar ...) )
Solution: Use the maximum value of the adjacent point as the weight value instead of the distance of the path to run the shortest or smallest spanning tree. And then I wrote a Dijkstra that I thought was an optimized one, but it was like prim--ah, pretty much.
In short, with priority queue maintenance weights for wide search ... And then pay g++ always wa also don't know why ... C + + has been handed over ...
Code:
#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 longusing namespace std;struct node{int x, y;} p[205];struct node1{int point; int step; Node1 (int, int step): 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];d ouble 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, & AMP;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;}
POJ 2253 Difference of clustering