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 遇到这种坐标求距离的最好就是输入double精确度高,然后并查集 代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <string>
#include <cmath>
using namespace std;
int n,d,p,q;
char ch;
int f[];
int stack[],head;
struct loc
{
double x,y;
int id;
}ro[];
void init()
{
for(int i=;i<=n;i++)
f[i]=i;
}
int getf(int x)
{
if(x!=f[x])f[x]=getf(f[x]);
return f[x];
}
int merge(int x,int y)
{
int xx=getf(x),yy=getf(y);
f[yy]=xx;
}
void check(int a,int b)
{
if(sqrt(pow(ro[a].x-ro[b].x,)+pow(ro[a].y-ro[b].y,))<=d)merge(a,b);
}
int main()
{
scanf("%d %d",&n,&d);
init();
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&ro[i].x,&ro[i].y);
} while(cin>>ch)
{
if(ch=='O')
{
scanf("%d",&p);
stack[head++]=p;
for(int i=;i<head-;i++)
{
check(stack[i],p);
}
}
else
{
scanf("%d %d",&p,&q);
if(getf(p)==getf(q))cout<<"SUCCESS"<<endl;
else cout<<"FAIL"<<endl;
}
}
}

Wireless Network 并查集的更多相关文章

  1. POJ 2236 Wireless Network (并查集)

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

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

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

  3. poj 2236 Wireless Network (并查集)

    链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...

  4. POJ 2236 Wireless Network [并查集+几何坐标 ]

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

  5. POJ2236 Wireless Network 并查集

    水题 #include<cstdio> #include<cstring> #include<queue> #include<set> #include ...

  6. [LA] 3027 - Corporative Network [并查集]

    A very big corporation is developing its corporative network. In the beginning each of the N enterpr ...

  7. LA 3027 Corporative Network 并查集记录点到根的距离

    Corporative Network Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [S ...

  8. UVALive - 3027 Corporative Network (并查集)

    这题比较简单,注意路径压缩即可. AC代码 //#define LOCAL #include <stdio.h> #include <algorithm> using name ...

  9. 【转】并查集&MST题集

    转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基 ...

随机推荐

  1. Confluence 6 连接一个目录

    你可以添加下面类型的目录服务器和目录管理器: Confluence 的内部目录(Configuring the Internal Directory). Microsoft Active Direct ...

  2. Nikita and stack CodeForces - 756C (栈,线段树二分)

    大意: 给定m个栈操作push(x)或pop(), 栈空时pop()无作用, 每个操作有执行的时间$t$, 对于每个$0 \le i \le m$, 输出[1,i]的栈操作按时间顺序执行后栈顶元素. ...

  3. mysql语句查询时间检测

    explain的使用 1.首先我们是要登入你的mysql的,然后选择数据库输入:use 你要选择的库名 2执行语句 eg:  explain SELECT * FROM wish_orders1412 ...

  4. jquery自动填充输入框

    1,这是一个比较简单的页面,你可以复制下来就可以使用.<!doctype html><html lang="en"><head> <met ...

  5. Intel daal4py demo运行过程

    daal安装(记得先安装anaconda): git clone https://github.com/IntelPython/daal4py.git cd daal4py conda create ...

  6. python中字符串连接的四种方式

    以下实例展示了join()的使用方法 #!/usr/bin/python str = "-"; seq = ("a", "b", " ...

  7. HDU 3697贪心

    额...大意是你可以决定什么时候选课.然后呢.每五分钟只有一次机会选.每种课限制选课时间.问你能选到的课最多有多少. 感觉一点都不水.是自己太菜了吗? #include<stdio.h> ...

  8. sql 判断字符串中是否含有数字和字母

    判断是否含有字母 select PATINDEX('%[A-Za-z]%', ‘ads23432’)=0 (如果存在字母,结果<>1) 判断是否含有数字 PATINDEX('%[0-9]% ...

  9. 微信小程序-隐藏和显示自定义的导航

    微信小程序中不能直接操作window对象,document文档,跟html的树结构不相同. 实现类似导航的隐藏显示,如图效果: 点击网络显示或隐藏网络中包含的内容.其他类似. 如果是jquery很方便 ...

  10. 离线部署 Cloudera Manager 5 和 CDH 5.12.1 及使用 CDH 部署 Hadoop 集群服务

    Cloudera Manager Cloudera Manager 分为两个部分:CDH和CM. CDH是Cloudera Distribution Hadoop的简称,顾名思义,就是cloudera ...