Wireless Network

Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 28617   Accepted: 11842

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

 
简单并查集
 //2017-07-17
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int N = ;
int n, d;
int fa[N], x[N], y[N];
bool isRepaired[N]; void init(){
for(int i = ; i < N; i++){
fa[i] = i;
isRepaired[i] = false;
}
} int getfa(int x){
if(fa[x] == x)return x;
return fa[x] = getfa(fa[x]);
} void merge0(int a, int b){
int af = getfa(a);
int bf = getfa(b);
if(af != bf){
fa[bf] = af;
}
} int main(){
char op[];
int a, b;
while(scanf("%d%d", &n, &d) != EOF){
init();
for(int i = ; i <= n; i++){
scanf("%d%d", &x[i], &y[i]);
}
getchar();
while(scanf("%s", op)!=EOF){
if(op[] == 'O'){
scanf("%d", &a);
isRepaired[a] = true;
for(int i = ; i <= n; i++){
if(isRepaired[i] && (x[i]-x[a])*(x[i]-x[a])+(y[i]-y[a])*(y[i]-y[a])<=d*d){
merge0(i, a);
}
}
}else{
scanf("%d%d", &a, &b);
int af = getfa(a);
int bf = getfa(b);
if(af == bf) printf("SUCCESS\n");
else printf("FAIL\n");
}
}
} return ;
}

POJ2236(KB5-A)的更多相关文章

  1. POJ2236

    https://vjudge.net/problem/POJ-2236 An earthquake takes place in Southeast Asia. The ACM (Asia Coope ...

  2. POJ-2236(并查集)

    Wireless NetWork POJ-2236 需要注意这里的树的深度需要初始化为0. 而且,find函数需要使用路径压缩,这里的unint合并函数也使用了优化(用一开始简单的合并过不了). #i ...

  3. 并查集 poj2236

    网址:http://poj.org/problem?id=2236 题意:有n台坏的电脑,如果每两台电脑的距离不能超过d,那么这两台电脑有联系,用字符串O 表示标记第x台电脑维修了,用S判断从X到y是 ...

  4. poj2236(并查集)

    题目链接: http://poj.org/problem?id=2236 题意: 有n台计算机, 已知每台计算机的坐标, 初始时所有计算机都是坏的, 然后修复其中一些计算机, 已修复的计算机距离不超过 ...

  5. poj-2236 Wireless Network &&poj-1611 The Suspects && poj-2524 Ubiquitous Religions (基础并查集)

    http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由 ...

  6. POJ2236 Wireless Network

    解题思路:简单并查集,注意时间限制是10000MS,每次进行O操作之后,   进行一次for循环,进行相关调整.同时注意输入输出格式,见代码: #include<cstdio> #incl ...

  7. POJ2236 Wireless Network 并查集

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

  8. poj2236 基础并查集

    题目链接:http://poj.org/problem?id=2236 题目大意:城市网络由n台电脑组成,因地震全部瘫痪,现在进行修复,规定距离小于等于d的电脑修复之后是可以直接相连 进行若干操作,O ...

  9. poj2236(并查集)

    题目连接 题意:一张图上分布着n台坏了的电脑,并知道它们的坐标.两台修好的电脑如果距离<=d就可以联网,也可以通过其他修好的电脑间接相连.给出操作“O x”表示修好x,给出操作“S x y”,请 ...

  10. poj2236无线网络

    这一题的大意:在救灾当中需要用网络,这堆人就用笔记本建了一个无线网,但是来,互相通信都是有距离限制的,一台电脑只能和距离他为d的电脑通信,然后一台电脑也可以通过几台电脑搭成线这样通信.然后就是输入每台 ...

随机推荐

  1. LOJ#3048. 「十二省联考 2019」异或粽子(trie树+堆)

    题面 传送门 题解 我们先把它给前缀异或和一下,然后就是要求前\(k\)大的\(a_i\oplus a_j\).把\(k\)乘上个\(2\),变成前\(2k\)大的\(a_i\oplus a_j\), ...

  2. 利用Python做绝地科学家(外挂篇)

    i春秋作家:奶权 前言  玩吃鸡时间长的鸡友们 应该都知道现在的游戏环境非常差 特别在高端局 神仙满天飞 搞得很多普通玩家非常没有游戏体验  因为吃鸡的火爆 衍生出了一条巨大的外挂利益链 导致市面上出 ...

  3. ProxySQL 部署 Single Writer Failover 读写分离 (PXC)

    主机信息: Proxysql: 如果你忽略了ProxySQL会报告主机组的变化,我建议把它设置为0,除非你试图调试"某些东西",否则你的日志将很快变得巨大.UPDATE globa ...

  4. python爬虫----XPath

    1.知道本节点元素,如何定位到兄弟元素 详情见博客 XML代码见下 bt1在文档中只出现一次,所以很容易获取到bt1中内容,那怎么根据<td class='bt1'>来获取bt2中的内容 ...

  5. 06-02 Java值传递、数据加密

    值传递: /* 思考题1:看程序写结果,然后分析为什么是这个样子的.并画图讲解.最后总结Java中参数传递规律. Java中的参数传递问题: 基本类型:形式参数的改变对实际参数没有影响.基本类型传递的 ...

  6. 解决当FORM的ENCTYPE="multipart/form-data" 时request.getParameter()获取不到值的方法

    部分转载于: http://blog.csdn.net/georgejin/article/details/1706647 http://www.cnblogs.com/loveyunk/p/6089 ...

  7. Enterprise Library 6 学习笔记

    今天是2014年上班第一天,想着今年要做点与往年不同的事情,就从写博客开始吧. 公司的项目一般都用微软的企业库,一直没时间好好研究,第一天上班还不忙,就抽空研究了下.搜索一下,发现这个企业库已经到了6 ...

  8. Android面试题(2)

    1.  int 和 Integer 有什么区别 Java 提供两种不同的类型:引用类型和原始类型(或内置类型).Int是java的原始数据类型,Integer是java为int提供的封装类.Java为 ...

  9. JavaScript -- Document-ElementsByName

    -----047-Document-ElementsByName.html----- <!DOCTYPE html> <html> <head> <meta ...

  10. 第三方登录:QQ登录实现(OAuth2.0)

    一.创建应用 1.在 QQ互联 创建应用 地址:https://connect.qq.com/manage.html#/ 然后进行实名认证,创建应用,审核通过 然后点击查看,可以获得 APP ID 和 ...