POJ 2236 (Simple and set) Wireless Network

Source: Internet
Author: User
Tags define local

Test instructions

There are n computers that have broken down, giving their coordinates separately.

There are two actions, can o X means to repair x computer, can S x y indicates whether X y is connected

The distance between the two computers is not more than D can be connected, two computers are connected can be directly connected or indirectly through a third computer connected

Ideas:

Every time I fix a computer, I compare it with a computer that has already been repaired. If the distance is less than D and is not on the same network, then merge together

1 //#define LOCAL2#include <iostream>3#include <cstdio>4#include <cstring>5 using namespacestd;6 7 Const intMAXN = ++Ten;8 structPos9 {Ten     intx, y; One }POS[MAXN]; A  - intP[MAXN], O[MAXN]; -  the intFind (inta) - { -     returnP[a] = = a? A:p[a] =Find (P[a]); - } +  - voidUnion (intAintb) + { A     intPA =Find (a); at     intPB =Find (b); -     if(PA! =pb) -P[PA] =PB; - } -  - intMainvoid) in { - #ifdef LOCAL toFreopen ("2236in.txt","R", stdin); +     #endif -  the     intN, D, a, B, cnt =0; *     Charcmd[Ten]; $scanf"%d%d", &n, &d);Panax Notoginseng      for(inti =0; I <= N; ++i) P[i] =i; -Memset (O,false,sizeof(o)); the      for(inti =1; I <= N; ++i) +scanf"%d%d", &pos[i].x, &pos[i].y); A      while(SCANF ("%s", cmd)! =EOF) the     { +         if(cmd[0] =='O') -         { $scanf"%d", &a); $o[cnt++] =A; -              for(inti =0; I < CNT-1; ++i) -             { the                 if((pos[a].x-pos[o[i]].x) * (pos[a].x-pos[o[i]].x) + (POS[A].Y-POS[O[I]].Y) * (POS[A].Y-POS[O[I]].Y) <= d *d) -                 {Wuyi Union (A, o[i]); the                 } -             } Wu         } -         Else About         { $scanf"%d%d", &a, &b); -             if(Find (a) = =Find (b)) -Puts"SUCCESS"); -             Else APuts"FAIL"); +         } the     } -  $     return 0; the}
code June

POJ 2236 (Simple and set) 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.