poj-2236 Wireless Network (base and check)

Source: Internet
Author: User

http://poj.org/problem?id=2236

As a result of the earthquake, the organization of the group put a lap of computer a wireless network, but because of the destruction of aftershocks, all the computer has been damaged, with the computer has been repaired, the wireless network gradually resumed work, but due to hardware constraints, a computer and another computer can be connected when they are less than the distance between D, Or a computer as an intermediary, connected to two computers, respectively.

During the repair process, the worker will have two actions, repair the computer and ask if Computer A and computer B are connected. When asked, output the answer.

Because the input data is very big, need to quickly judge computer A and computer B connected, so naturally think of using and check set.

The initial time all the computer is damaged, then each repair, you need to the current computer distance is less than D and has been repaired computer connection, when asked to directly judge.

1#include <cstdio>2#include <cmath>3#include <cstring>4 using namespacestd;5 Const intMAXN =1010;6 structnode7 {8     intx, y;9 }P[MAXN];Ten intPAR[MAXN],FLAG[MAXN];//as a mark of whether to repair One intN; A DoubleDIS[MAXN][MAXN];//stores the distance between two points - DoubleD; - voidInit () the { -      for(intI=1; i<=n;i++) par[i]=i; - } -  + intFindintx) - { +     returnx==par[x]?x:par[x]=find (Par[x]); A } at  - voidUniteintXinty) - { -x=find (x); -y=find (y); -     if(x!=y) inpar[x]=y; - } to  + voidDistanceintAintb) - { theDIS[A][B]=DIS[B][A]=SQRT (1.0* (p[a].x-p[b].x) * (p[a].x-p[b].x) +1.0* (P[A].Y-P[B].Y) * (p[a].y-p[b].y)); * } $ Panax Notoginseng voidSolveintx) - { the      for(intI=1; i<=n;i++) +     { A         if(i!=x&&flag[i]&&dis[x][i]<=d) the Unite (x,i); +     } - } $  $ intMain () - { -    //freopen ("A.txt", "R", stdin); thescanf"%D%LF",&n,&d); - init ();Wuyimemset (Flag,0,sizeof(flag)); thememset (DIS,0,sizeof(DIS)); -      for(intI=1; i<=n;i++) Wuscanf"%d%d",&p[i].x,&p[i].y); -      for(intI=1; i<=n;i++)//preprocessing the distance between all two points About          for(intj=i+1; j<=n;j++) $ distance (i,j); -     Chars[2]; -     intb; -      while(~SCANF ("%s", s)) A     { +         if(s[0]=='O') the         { -scanf"%d",&a); $flag[a]=1; the solve (a); the         } the         Else if(s[0]=='S') the         { -scanf"%d%d",&a,&b); in             if(Find (a) ==find (b)) printf ("success\n"); the             Elseprintf"fail\n"); the         } About     } the     return 0; the}

poj-2236 Wireless Network (base and check)

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.