POJ2236 Wireless Network (Easy)

Source: Internet
Author: User

Description

An earthquake takes place in southeast Asia. The ACM (Asia cooperated Medical team) has set up a wireless network with the lap computers, but an unexpected aftershock Attacked, all computers on the network were all broken. The computers is repaired one by one, and the network gradually began to work again. Because of the hardware restricts, each computer can only directly communicate with the computers that is not farther tha n d meters from it. But every computer can be regarded as the intermediary of the communication between and the other computers, that's to say Co Mputer A and Computer B can communicate if computer A and computer B can communicate directly or there is A computer C tha T can communicate with both A and B.

In the process of repairing the network, workers can take the other kinds of operations at every moment, repairing a computer, O R Testing if computers can communicate. Your job is to answer all the testing operations.

The main idea: An earthquake destroyed all the computers (should I say the power of earthquake?) Or the computer is too ruo ... Give the coordinates of each computer, two computers can be connected, when the two computers can be directly connected or have an intermediary computer can be connected to the intermediate computer directly. Two kinds of operation: O ——— repair the computer, s--query two computers can connect, output "SUCCESS", otherwise output "FAIL".
Idea: preprocessing the distance between computers, simple and check set, online practice, each repair a computer should be poor lift all the distance is less than equal to the computer, and update.
(Distance is Euler distance, with the square to save the good, notice D to First square)

Code
#include <iostream> #include <cstdio>using namespace Std;int dis[1010][1010]={0},ad[1010][2]={0},fa[1010 ]={0};bool visit[1010]={false};int rool (int x) {if (fa[x]!=x) Fa[x]=rool (fa[x]); return fa[x];} int main () {int N,i,j,r1,r2,d,a,b;char kind;cin>>n>>d;d=d*d;for (i=1;i<=n;++i)  fa[i]=i;for (i=1; I<=n;++i) { scanf ("%d%d", &ad[i][0],&ad[i][1]);  for (j=1;j<i;++j)    dis[j][i]= Dis[i][j]= (Ad[i][0]-ad[j][0]) * (ad[i][0]-ad[j][0]) +                    (Ad[i][1]-ad[j][1]) * (ad[i][1]-ad[j][1]);   }while (scanf ("%*c%c", &kind) ==1) {if (kind== ' O ') {  scanf ("%d", &a);     r1=rool (a);     for (i=1;i<=n;++i)         if (Dis[i][a]<=d&&visit[i])        {       r2=rool (i);    & nbsp  if (R1!=R2)          fa[r2]=r1;       }&nbsp    visit[a]=true;} ELSE{SCANF ("%d%d", &a,&b); R1=rool (a); R2=rool (b); if (R1!=R2)  printf ("%s\n", "FAIL"), Else printf ("%s\n" , "SUCCESS");}}}  

POJ2236 Wireless Network (easy)

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.