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. onWindowFocusChanged-屏幕焦点函数回调情况

    1.这个函数的具体作用不太清楚,但网上有人说是 ,当activity得到或者失去焦点的时候,就会调用这个方法 先看如下代码 @Override public void onWindowFocusCha ...

  2. PHP服务器环境打开配置文件

    MAC 1.  cd /usr/local/etc/nginx/servers vim www.xxx.com 2. 在/usr/local/etc/nginx/servers目录下,不同的 .con ...

  3. Java Web学习总结(12)——使用Session防止表单重复提交

    在平时开发中,如果网速比较慢的情况下,用户提交表单后,发现服务器半天都没有响应,那么用户可能会以为是自己没有提交表单,就会再点击提交按钮重复提交表单,我们在开发中必须防止表单重复提交. 一.表单重复提 ...

  4. Dcloud课程1 APP的架构有哪些

    Dcloud课程1 APP的架构有哪些 一.总结 一句话总结:B/S架构和C/S构架 1.APP的分类? 主流的四大APP系统:1.苹果ios系统版本,开发语言是Objective-C:2.微软Win ...

  5. Transact-SQL语法速查手册

    第1章 Transact-SQL基础 1.1 标识符 一.常规标识符 1. 命名规则: l 第一个字母必须是Unicode2.0标准定义的字母.下划线.at符号(@)和数字符号(#): l 后续字符可 ...

  6. js进阶 12-17 jquery实现鼠标左键按下拖拽功能

    js进阶 12-17 jquery实现鼠标左键按下拖拽功能 一.总结 一句话总结:监听的对象必须是文档,鼠标按下运行mousemove事件,鼠标松开取消mousemove事件的绑定,div的偏移的话是 ...

  7. WCF 设计和实现服务协定(01)

    作者:jiankunking 出处:http://blog.csdn.net/jiankunking WCF 术语: • 消息 – 消息是一个独立的数据单元,它可能由几个部分组成,包含消息正文和消息头 ...

  8. [Angular2 Form] Reactive Form, FormBuilder

    Import module: import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/comm ...

  9. /bin/bash^M: bad interpreter: 没有那个文件或文件夹

    执行脚本时出现了这样一个错误,打开之后并没有找到所谓的^M,查了之后才知道原来是文件格式的问题,也就是linux和windows之间的不全然兼容... 详细细节无论,假设验证: vim test.sh ...

  10. sqoop 1.4.4-cdh5.1.2快速入门 分类: C_OHTERS 2015-06-06 11:40 208人阅读 评论(0) 收藏

    一.快速入门 (一)下载安装 1.下载并解压 wget http://archive.cloudera.com/cdh5/cdh/5/sqoop-1.4.4-cdh5.1.2.tar.gz tar - ...