Wireless Network
Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 20724   Accepted: 8711

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.

Input

The first line contains two integers N and d (1 <= N <= 1001, 0 <= d <= 20000). Here N is the number of computers, which are numbered from 1 to N, and D is the maximum distance two computers can communicate directly. In the next N lines, each contains two integers xi, yi (0 <= xi, yi <= 10000), which is the coordinate of N computers. From the (N+1)-th line to the end of input, there are operations, which are carried out one by one. Each line contains an operation in one of following two formats: 
1. "O p" (1 <= p <= N), which means repairing computer p. 
2. "S p q" (1 <= p, q <= N), which means testing whether computer p and q can communicate.

The input will not exceed 300000 lines.

Output

For each Testing operation, print "SUCCESS" if the two computers can communicate, or "FAIL" if not.

Sample Input

4 1
0 1
0 2
0 3
0 4
O 1
O 2
O 4
S 1 4
O 3
S 1 4

Sample Output

FAIL
SUCCESS
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <cmath>
using namespace std;
#define Max 1005
int n,d;
int per[Max];
bool vis[Max];
struct point
{
int x,y;
}e[];
void init()
{
for(int i=;i<=n;i++)
per[i]=i;
return;
}
int find(int x)
{
if(x==per[x])
return x;
int tem,root=x,t=x;
while(root!=per[root]) root=per[root];
while(t!=per[t])
{
tem=per[t];
per[t]=root;
t=tem;
}
}
bool dis(int q,int p)
{
point a=e[q],b=e[p];
int f=(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
return d*d>=f;
}
int unite(int a,int b)
{
a=find(a);
b=find(b);
if(a!=b)
per[a]=b;
return ;
}
int main()
{
int i,j;
int v,u,p;
char ch;
freopen("in.txt","r",stdin);
scanf("%d%d",&n,&d);
init();
memset(vis,,sizeof(vis));
for(i=;i<=n;i++)
scanf("%d%d",&e[i].x,&e[i].y);
getchar();
while(scanf("%c",&ch)!=EOF)
{
if(ch=='S')
{
scanf("%d%d",&u,&v);
if(find(u)==find(v))
printf("SUCCESS\n");
else
printf("FAIL\n");
}
else if(ch=='O')
{
scanf("%d",&u);
vis[u]=;
for(i=;i<=n;i++)
if(vis[i]&&i!=u&&dis(i,u))
unite(u,i);
}
getchar();
}
return ;
}

Wireless Network(POJ 2236)的更多相关文章

  1. Day5 - B - Wireless Network POJ - 2236

    An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...

  2. (并查集) Wireless Network --POJ --2236

    链接: http://poj.org/problem?id=2236 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...

  3. DisJSet:Wireless Network(POJ 2236)

      无线电网络 题目大意:就是地震后,所有的电脑都坏了,现在可以修复,而且要重新连成一个网络,两台电脑之间最大连接距离为D,两台电脑可以有中继电脑,按O修复电脑,按S测试两台电脑是否有链接,如果有就输 ...

  4. Wireless Network POJ - 2236 (并查集)

    #include<iostream> #include<vector> #include<string> #include<cmath> #includ ...

  5. A - Wireless Network POJ - 2236

    题目大意:有n台坏掉的电脑,给出每台电脑的坐标,然后每次询问输入0(字符) x,表示电脑x恢复正常,输入S x y 询问x和y是否可以联网.只要是x和y的距离小于距离d,那么就可以联网,如果有个中介c ...

  6. A - Wireless Network POJ - 2236-kuangbin带你飞

    A - Wireless Network POJ - 2236 Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 50348 ...

  7. POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集

    POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...

  8. [并查集] POJ 2236 Wireless Network

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 25022   Accepted: 103 ...

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

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 677 ...

随机推荐

  1. 畅通工程再续--hdu1875

    畅通工程再续 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  2. 《Programming WPF》翻译 第8章 2.Timeline

    原文:<Programming WPF>翻译 第8章 2.Timeline Timeline代表了时间的延伸.它通常还描述了一个或多个在这段时间所发生的事情.例如,在前面章节描述的动画类型 ...

  3. 车祸 shit

    今天上班的时候就觉得右眼在那跳,妈的,果不其然,回家路上自行车也跟人家撞上了,郁闷,裤子也坏了,腿也伤了.我还没反应过来,撞一起的是个女的,十七八岁吧,郁闷,什么破自行车.强烈呼吁不要去买小自行车了, ...

  4. 【转】Android兼容性测试CTS Verifier-环境搭建、测试执行、结果分析

    原文网址:http://www.cnblogs.com/zh-ya-jing/p/4452675.html CTS Verifier算是CTS的一部分,需要手动进行,主要用于测试那些自动测试系统无法测 ...

  5. hdu 4504 威威猫系列故事——篮球梦_简单dp

    题目链接 题意:你现在分数为a,对方分数为b,你比赛还有n分钟,每次进攻需要15分钟,现在你先进攻,每次进攻可以得1或2或3,对方每次进攻得一分,问超过对方分数有多少种打法 思路:因为情况太多要用__ ...

  6. poj 3045 Cow Acrobats(二分搜索?)

    Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away a ...

  7. C#中通过位运算实现多个状态的判断

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. 2D丛林逃生

    游戏介绍: 游戏地图采用二维数组:     每一个小块(Piece)类         上面有一个类型(StuffType)用于判断该小块上面站着的是什么 怪物,玩家,血瓶等等     怪物AI:   ...

  9. NTP配置实践

    前言 NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议.不管是平时使用的私人计算机还是在工作中搭建的服务器集群.时间的统一性和准确性是十分 ...

  10. Working with Numbers in PL/SQL(在PL/SQL中使用数字)

    This article gives you all the information you need in order to begin working with numbers in your P ...