"And check set" Poj2236-wireless Network

Source: Internet
Author: User

"The main topic"

It is known that each computer can only be connected to a computer with a distance of D, but the two computers can be connected by a third computer as a medium. The computer is all damaged now. You can do one of two operations at a time, or fix a computer, or check whether two computers are connected.

Ideas

Obviously it's a collection. Every time a new computer is repaired, it is judged by each computer that was previously repaired, and the distance is merged within D.

1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 Const intmaxn=1001+ -;6 intn,d;7 intX[MAXN],Y[MAXN],REP[MAXN];8 intH[MAXN],PA[MAXN];9 Ten intIndintAintb) One { A     return((X[a]-x[b]) * (X[a]-x[b]) + (Y[a]-y[b]) * (Y[a]-y[b]) <=d*d); - } -  the voidNewset () - { -      for(intI=0; i<n;i++) -     { +h[i]=0; -pa[i]=i; +     } A } at  - intFindintx) - { -     intR=x; -      while(pa[r]!=r) r=Pa[r]; -     intp=x; in      while(pa[p]!=R) -     { to         inttemp=Pa[p]; +pa[p]=R; -p=temp; the     } *     returnR; $ }Panax Notoginseng  - voidUnionset (intFaintFB) the { +     if(h[fa]>=H[FB]) A     { thepa[fb]=FA; +         if(H[FA]==H[FB]) h[fa]++; -     } $     Else $pa[fa]=FB; - } -  the intMain () - {Wuyiscanf"%d%d",&n,&d); the      for(intI=0; i<n;i++) -     { Wuscanf"%d%d",&x[i],&y[i]); -     } About      $     CharC; -     intRepd=0;//òñ¾ðþºãµäµçäôêýá¿ - Newset (); -      A GetChar (); +      while(SCANF ("%c", &c)! =EOF) the     { -         if(c=='S') $         { the             intb; thescanf"%d%d",&a,&b); thea--; theb--; -             if(Find (a) ==find (b)) cout<<"SUCCESS"<<endl;Elsecout<<"FAIL"<<Endl; in         } the          the         Else About         { the             intA; thescanf"%d",&a); thea--; +              for(intI=0; i<repd;i++) -             { the                 if(Ind (A,rep[i]))Bayi                 { the                     intFa=find (a), fb=find (Rep[i]); the Unionset (FA,FB); -                 } -             } therep[repd]=A; therepd++; the         } the GetChar (); -     } the     return 0; the}

"And check set" Poj2236-wireless Network

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.