id=11125" target="_blank" style="color:blue; text-decoration:none">POJ - 2236

Time Limit: 10000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

id=11125" class="login ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:0.1em; vertical-align:middle; overflow:visible; text-decoration:none; font-family:Verdana,Arial,sans-serif; border:1px solid rgb(211,211,211); color:blue; font-size:12px!important">Submit Status

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
首先要看懂题目的意思。首先要进行通信,首先你的电脑必须已经修好,否则是不可以通信的,并且通信时距离在一定范围内才可以实现
/*
Author: 2486
Memory: 380 KB Time: 3063 MS
Language: G++ Result: Accepted
*/
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn=10000+5;
int N,d;
char op[10];
int par[maxn],ranks[maxn];
bool vis[maxn];//代表着是否已经修复了电脑,电脑是否正常
struct co {
int x,y;
} coh[maxn];
void init(int sizes) {
for(int i=0; i<=sizes; i++) {
par[i]=i;
ranks[i]=1;
}
}
int find(int x) {
return par[x]==x?x:par[x]=find(par[x]);
}
bool same(int x,int y) {
return find(x)==find(y);
}
bool judge(int x,int y) {
return pow((coh[x].x-coh[y].x),2.0)+pow((coh[x].y-coh[y].y),2.0)<=pow(d,2.0);//推断距离是否符合条件
}
void unite(int x,int y) {
x=find(x);
y=find(y);
if(x==y)return ;
if(ranks[x]>ranks[y]) {
par[y]=x;
} else {
par[x]=y;
if(ranks[x]==ranks[y])ranks[x]++;
}
}
int main() {
int c,e;
scanf("%d%d",&N,&d);
init(N);
memset(vis,false,sizeof(vis));
for(int i=1; i<=N; i++) {
scanf("%d%d",&coh[i].x,&coh[i].y);
}
while(~scanf("%s",op)) {
if(op[0]=='O') {
scanf("%d",&c);
vis[c]=true;
for(int i=1; i<=N; i++) {
if(vis[i]&&judge(c,i)) {//与其它的电脑进行联系的前提是他们是好的,假设不好就连接不上
unite(c,i);
}
}
} else {
scanf("%d%d",&c,&e);
if(vis[c]&&vis[e]&&same(c,e)) {//是否通信。要看电脑是否已经修复完毕
printf("SUCCESS\n");
} else printf("FAIL\n");
}
}
return 0;
}

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

  1. POJ 2236 Wireless Network (并查集)

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

  2. poj 2236 Wireless Network (并查集)

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

  3. poj 2236【并查集】

    poj 2236 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical t ...

  4. poj 2524 (并查集)

    http://poj.org/problem?id=2524 题意:在一所学校里面的人,都有宗教信仰,不过他们的宗教信仰有可能相同有可能不同,但你又不能直接去问他们,但你可以问他们和谁是同一个宗教.通 ...

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

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

  6. [POJ 2588]--Snakes(并查集)

    题目链接:http://poj.org/problem?id=2588 Snakes Time Limit: 1000MS   Memory Limit: 65536K   Description B ...

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

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

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

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

  9. poj 1456 Supermarket - 并查集 - 贪心

    题目传送门 传送点I 传送点II 题目大意 有$n$个商品可以销售.每个商品销售会获得一个利润,但也有一个时间限制.每个商品需要1天的时间销售,一天也只能销售一件商品.问最大获利. 考虑将出售每个物品 ...

  10. poj 2492(关系并查集) 同性恋

    题目;http://poj.org/problem?id=2492 卧槽很前卫的题意啊,感觉节操都碎了, t组测试数据,然后n,m,n条虫子,然后m行,每行两个数代表a和b有性行为(默认既然能这样就代 ...

随机推荐

  1. Vue的学习--怎么在vue-cli中写网页

    vue.min.js和vue-cli的区别和联系我现在还是没有太清楚,大概是还没搞清楚export default和new Vue的区别,先浅浅记录一下怎么“用vue-cli来写网页”. “vue-c ...

  2. leaf cell

    leaf cell是否可以理解为设计中与或非门等这些基本的单元?

  3. DTU(用于将串口数据转换为IP数据或将IP数据转换为串口数据通过无线通信网络进行传送的无线终端设备)

    DTU (Data Transfer unit),是专门用于将串口数据转换为IP数据或将IP数据转换为串口数据通过无线通信网络进行传送的无线终端设备.DTU广泛应用于气象.水文水利.地质等行业.

  4. 移动mm 话费支付接入过程(ane)

    下面记录移动mm 话费支付接入的过程 1.强联网.弱联网差别.sdk是否有区分?用户体验部分由什么不同和差异? 差别在于强联网是网络通道(wifi/gprs/3g),弱联网是走短信通道,用户层面差异在 ...

  5. 【Expression 序列化】WCF的简单使用及其Expression Lambada的序列化问题初步解决方案

    地址:http://www.cnblogs.com/guomingfeng/tag/Expression%E5%BA%8F%E5%88%97%E5%8C%96/

  6. CODEVS——T 1993 草地排水 USACO

    http://codevs.cn/problem/1993/  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 De ...

  7. FZU Problem 2168 防守阵地 I

    http://acm.fzu.edu.cn/problem.php?pid=2168 题目大意: 给定n个数和m,要求从n个数中选择连续的m个,使得a[i]*1+a[i+1]*2+--a[i+m]*m ...

  8. CentOS 6 通过DVD快速建立本地YUM源

    一.将DVD光盘放入RedHat/CentOS6.X服务器/电脑光驱中 二.挂载DVD光驱到/mnt/cdrom # mkdir -p /mnt/cdrom # mount -t iso9660 /d ...

  9. postman和fiddler的基本使用

    本文转自:https://www.cnblogs.com/qq909283/p/6826578.html 写在前面:本文主要的章节规划: 1.什么是接口测试 另外,有的时候会直接调用别的公司的接口,比 ...

  10. 短网址ShortUrl的算法

    场景: 我们在新浪微博上公布网址的时候.微博会自己主动判别网址.并将其转换.比如:http://t.cn/hrYnr0. 为什么要这样做的,原因我想有这样几点: 1.微博限制字数为140字一条,那么假 ...