Wireless Network (POJ-2236) (also set)

Source: Internet
Author: User

Because the number of queries may be many, interrelated computers may also be many, and the relationship between each computer only merge relationship and query, matching and check set characteristics.

And look for a more biased template point, there is no difficulty in thinking, as long as the grasp of the need to use and check the set of conditions is good.

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <    Queue> #include <map>using namespace Std;int n,d,vis[1111],rankk[1010],par[1020];struct Point {int x, y; Point (int x = 0,int y = 0): x (x), Y (y) {} bool operator < (const point& r) Const {return x<r.x | | x==r.x &am p;& y<r.y;        }} a[1111];void init (int n) {for (int i=1;i<=n;i++) {Par[i] = i;    Rankk[i] = 0; }}int findd (int x) {return par[x]==x? x:par[x] = Findd (Par[x]);}    void Unite (int x,int y) {x = FINDD (x);    y = findd (y);    if (x==y) return;    if (Rankk[x]<rankk[y]) {par[x] = y;        } else {par[y] = x;    if (rankk[x] = = Rankk[y]) rankk[x]++; }}bool Same (int x,int y) {return findd (x) = = Findd (y);}    int main () {memset (vis,0,sizeof (VIS));    scanf ("%d%d", &n,&d);    for (int i=1;i<=n;i++) {scanf ("%d%d", &a[i].x,&a[i].y);    } Char s[10];    Init (n); int b,c;   while (scanf ("%s", s)!=eof) {if (s[0]== ' O ') {scanf ("%d", &b);            VIS[B] = 1; for (int i=1;i<=n;i++) {if (vis[i]&&i!=b) {int dd = (a[i].x-a[b].x) * (a[i].x-a                    [b].x] + (A[I].Y-A[B].Y) * (A[I].Y-A[B].Y);                if (dd<= (d*d)) unite (B,I);            }}}} else {scanf ("%d%d", &b,&c);            if (Same (b,c)) printf ("success\n");        else printf ("fail\n"); }} return 0;}


Wireless Network (POJ-2236) (also set)

Related Article

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.