POJ 2253 Difference of clustering

Source: Internet
Author: User

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 &AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.