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