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. RabbitMQ入门_12_发布方确认

    参考资料:https://www.rabbitmq.com/confirms.html 通过 ack 机制,我们可以确保队列中的消息一定能被消费到.那我们有办法保证消息发布方一定把消息发送到队列了吗? ...

  2. Codeforces 877E - Danil and a Part-time Job(dfs序+线段树)

    877E - Danil and a Part-time Job 思路:dfs序+线段树 dfs序:http://blog.csdn.net/qq_24489717/article/details/5 ...

  3. Codeforces 260B - Ancient Prophesy

    260B - Ancient Prophesy 思路:字符串处理,把符合条件的答案放进map里,用string类中的substr()函数会简单一些,map中的值可以边加边记录答案,可以省略迭代器访问部 ...

  4. Mac下使用源码编译安装TensorFlow CPU版本

    1.安装必要的软件 1.1.安装JDK 8 (1)JDK 8 can be downloaded from Oracle's JDK Page: http://www.oracle.com/techn ...

  5. 使用 Python 的 Socket 模块构建一个 UDP 扫描工具

    译文:oschina 英文:bt3gl 当涉及到对一些目标网络的侦察时,出发点无疑是首先发现宿主主机.这个任务还可能包含嗅探和解析网络中数据包的能力. 几周前,我曾经谈到了如何使用Wireshark来 ...

  6. Redis基础知识点面试手册

    Redis基础知识点面试手册 基础 概述 数据类型 STRING LIST SET HASH ZSET(SORTEDSET) 数据结构 字典 跳跃表 使用场景 会话缓存 缓存 计数器 查找表 消息队列 ...

  7. vijos1746 floyd

    小D的旅行 旅行是一件颇有趣的事情,但是在旅行前规划好路线也很重要. 现在小D计划要去U国旅行. U国有N个城市,M条道路,每条道路都连接着两个城市,并且经过这条道路需要一定的费用wi. 现在小D想要 ...

  8. ~递归递归(FBI树--蓝桥)

    1220: FBI树 [递归] 时间限制: 1 Sec 内存限制: 128 MB 提交: 5 解决: 4 状态 题目描述 我们可以把由“0”和“1”组成的字符串分为三类:全“0”串称为B串,全“1”串 ...

  9. 万恶的deferred_segment_creation(延迟块分配)

    11gR2开始,空表是不分配segment的.由于没有分配 segment, EXP默认不能导出空表,user_objects有该对象但是 user_segment没有该对象

  10. ubuntu下没有Language Support

    sudo apt-get installlanguage-selector-gnome