Wireless Network

Time Limit: 10000MS Memory Limit: 65536K

Total Submissions: 19626 Accepted: 8234

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

Source

POJ Monthly,HQM

并查集的应用,将可以连接在一起纳入一个集合,进行查找

#include <iostream>
#include <cmath>
#include <map>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <string>
#include <queue>
#include <algorithm>
#define LL long long
using namespace std; const int INF = 0x3f3f3f3f; const int MAX = 1100; int pre[MAX]; struct node
{
int x;
int y;
}a[MAX]; int n,d; bool vis[MAX]; int Find(int x)
{
return pre[x]==x?x:pre[x]=Find(pre[x]);
} int Dis(node b,node c)//计算距离
{
return ((b.x-c.x)*(b.x-c.x)+(b.y-c.y)*(b.y-c.y));
} int main()
{
char s[2];
scanf("%d %d",&n,&d);
for(int i=1;i<=n;i++)
{
pre[i]=i;
scanf("%d %d",&a[i].x,&a[i].y);
}
int site; int u,v; memset(vis,false,sizeof(vis)); while(~scanf("%s",s))
{
if(s[0]=='O')
{
scanf("%d",&site);
vis[site]=true;
int y = Find(site);
for(int i=1;i<=n;i++)
{
if(vis[i]&&i!=site)
{
int x = Find(i);
if(x!=y&&d*d>=Dis(a[site],a[i]))//这里判断错,应该让两个根节点连接
{
pre[x] = y;
}
}
}
}
else
{
scanf("%d %d",&u,&v);
if(Find(u)==Find(v))
{ printf("SUCCESS\n");
}
else
{
printf("FAIL\n");
}
}
}
return 0;
}

Wireless Network的更多相关文章

  1. [并查集] POJ 2236 Wireless Network

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

  2. POJ 2236 Wireless Network(并查集)

    传送门  Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 24513   Accepted ...

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

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

  4. Top 10 Free Wireless Network hacking/monitoring tools for ethical hackers and businesses

    There are lots of free tools available online to get easy access to the WiFi networks intended to he ...

  5. POJ 2236 Wireless Network (并查集)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 18066   Accepted: 761 ...

  6. POJ 2236 Wireless Network (并查集)

    Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...

  7. Wireless Network(POJ 2236)

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

  8. POJ - 2336 Wireless Network

    Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...

  9. POJ2236 Wireless Network 并查集简单应用

    Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...

随机推荐

  1. 当As3遇见Swift(二)

    字符串:String 都是用String来表示,都是值类型,在传递过程中都会进行拷贝. 计算字符数量 As3: str.length Swift: countElements(str) 数组:Arra ...

  2. Lintcode: Matrix Zigzag Traversal

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in ZigZag-or ...

  3. [转]-Dmaven.multiModuleProjectDirectory system propery is not set. 解决方案 适用于myeclipes 和 eclipes

    eclipse中使用maven插件的时候,运行run as maven build的时候报错 -Dmaven.multiModuleProjectDirectory system propery is ...

  4. Java编程思想(一):大杂烩

    在java中一切都被视为对象.尽管一切都是对象,但是操纵的标识符实际上是对象的一个引用,可以将引用想象成是遥控器(引用)来操纵电视机(对象).没有电视机,遥控器也可以单独存在,即引用可以独立存在,并不 ...

  5. POJ 2947 Widget Factory(高斯消元)

    Description The widget factory produces several different kinds of widgets. Each widget is carefully ...

  6. URAL 1876 Centipede's Morning(数学)

    A centipede has 40 left feet and 40 right feet. It keeps a left slippers and b right slippers under ...

  7. MVC3/4 自定义HtmlHelper截断文本内容(截取)

    在MVC目录下新建一个名为 Extersions  的文件夹,在该文件夹中新建一个截断文本类,取名为:CutOfTextExtersions 该类代码如下: using System; using S ...

  8. DOM事件处理有三个阶段

    DOM事件处理有三个阶段: 捕捉阶段(capture phase):从最上层元素,直到最下层(你点击的那个target)元素.路过的所有节点都可以捕捉到该事件. 命中阶段(target phase): ...

  9. zend

    1.导入一个已经存在的目录到空间 在空间左侧新建--->项目--->已经存在的目录

  10. 用jQuery创建HTML中不存在的标签元素碰到的问题

    如果你自定义了一个标签,比如<aaa></aaa> 用jQuery的写法,比如var custom_element = $('<aaa class="ee&qu ...