POJ2236 Wireless Network (easy)

Description

An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are 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 are not farther than d meters from it. But every computer can be regarded as the intermediary of the communication between two other computers, that is to say computer A and computer B can communicate if computer A and computer B can communicate directly or there is a computer C that can communicate with both A and B.

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

题目大意:一场地震毁了所有的电脑(我该说earthquake的威力大呢?还是电脑太RUO。。。)给出各电脑的坐标,两个电脑可以相连,当两电脑可以直接相连或者有一个中间电脑可以使之分别与中间电脑直接相连。两种操作:O ———修复电脑;S——查询两电脑能否连接,可以就输出“SUCCESS”,否则输出“FAIL”。

思路:预处理各电脑间的距离,简单的并查集,在线做法,每次修一台电脑都要穷举所有距离小于等于d的电脑,并更新。
(距离是欧拉距离,用平方保存就好了,注意d要先平方)

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);

if (r1!=r2)

fa[r2]=r1;

}

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");

}

}

}

时间: 2024-11-05 23:20:48

POJ2236 Wireless Network (easy)的相关文章

poj-2236 Wireless Network (基础并查集)

http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由于硬件的限制,一台电脑和另一台电脑能够相连当他们之间的距离小于d,或者还有一台电脑当中介,分别与两台电脑相连. 在修复的过程中,工作者会有两种操作,修复电脑和询问电脑a和电脑b是否相连.当询问的时候输出答案. 因为输入数据很大,需要快速判断电脑a和电脑b相连,所以自然想到用并查集. 初始时候 全部电

poj 2236:Wireless Network(并查集,提高题)

Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 6778 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computer

poj 1459 Power Network (dinic)

Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 23059   Accepted: 12072 Description A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied

poj 1861 Network (kruskal)

Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13633   Accepted: 5288   Special Judge Description Andrew is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the c

POJ2236 wireless network 【并查集水题】

前端开发whqet,csdn,王海庆,whqet,前端开发专家 今天是个好日子,2014年5月20日,表白的最佳时机,虽说孩子已经四岁.结婚已经五年,但是也不可以偷懒,于是有了这个效果. 在线研究点这里,下载收藏点这里.程序猿and程序媛,大胆秀出你的爱吧. 利用html5 canvas实现动态的文字粒子效果,效果如下. OK,简单看看原理,首先我们需要在canvas里面实现描边文字,然后利用getImageData获得描边文字的像素矩阵,将粒子效果绑定在描边文章上. 整个效果如下. html文

POJ2492 A Bug&#39;s Life (easy)

Description BackgroundProfessor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs a

POJ2236:Wireless Network(并查集)

Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 39772   Accepted: 16479 题目链接:http://poj.org/problem?id=2236 Description: An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a

【POJ - 2236】Wireless Network (并查集)

Wireless Network 这接翻译了 Descriptions 地震发生在东南亚.ACM(亚洲合作医疗团队)已经与膝上电脑建立了无线网络,但是一次意外的余震袭击,网络中的所有计算机都被打破了.计算机一个接一个地修复,网络逐渐开始工作.由于硬件限制,每台计算机只能直接与距离它不远的计算机进行通信.但是,每台计算机都可以被视为两台其他计算机之间通信的中介,也就是说,如果计算机A和计算机B可以直接通信,或者计算机C可以与A和A进行通信,则计算机A和计算机B可以进行通信. B. 在修复网络的过程

POJ - 2236 Wireless Network (并查集)

https://cn.vjudge.net/problem/POJ-2236 题意 有一个计算机网络的所有线路都坏了,网络中有n台计算机,现在你可以做两种操作,修理(O)和检测两台计算机是否连通(S),只有修理好的计算机才能连通.连通有个规则,两台计算机的距离不能超过给定的最大距离D(一开始会给你n台计算机的坐标).检测的时候输出两台计算机是否能连通. 分析 注意审题..只有修理好的才能算联通.于是把所有修理好的并一起就行了. #include <iostream> #include <