POJ2236(KB5-A)
Wireless Network
| Time Limit: 10000MS | Memory Limit: 65536K | |
| Total Submissions: 28617 | Accepted: 11842 |
Description
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
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
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)的更多相关文章
- POJ2236
https://vjudge.net/problem/POJ-2236 An earthquake takes place in Southeast Asia. The ACM (Asia Coope ...
- POJ-2236(并查集)
Wireless NetWork POJ-2236 需要注意这里的树的深度需要初始化为0. 而且,find函数需要使用路径压缩,这里的unint合并函数也使用了优化(用一开始简单的合并过不了). #i ...
- 并查集 poj2236
网址:http://poj.org/problem?id=2236 题意:有n台坏的电脑,如果每两台电脑的距离不能超过d,那么这两台电脑有联系,用字符串O 表示标记第x台电脑维修了,用S判断从X到y是 ...
- poj2236(并查集)
题目链接: http://poj.org/problem?id=2236 题意: 有n台计算机, 已知每台计算机的坐标, 初始时所有计算机都是坏的, 然后修复其中一些计算机, 已修复的计算机距离不超过 ...
- poj-2236 Wireless Network &&poj-1611 The Suspects && poj-2524 Ubiquitous Religions (基础并查集)
http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由 ...
- POJ2236 Wireless Network
解题思路:简单并查集,注意时间限制是10000MS,每次进行O操作之后, 进行一次for循环,进行相关调整.同时注意输入输出格式,见代码: #include<cstdio> #incl ...
- POJ2236 Wireless Network 并查集
水题 #include<cstdio> #include<cstring> #include<queue> #include<set> #include ...
- poj2236 基础并查集
题目链接:http://poj.org/problem?id=2236 题目大意:城市网络由n台电脑组成,因地震全部瘫痪,现在进行修复,规定距离小于等于d的电脑修复之后是可以直接相连 进行若干操作,O ...
- poj2236(并查集)
题目连接 题意:一张图上分布着n台坏了的电脑,并知道它们的坐标.两台修好的电脑如果距离<=d就可以联网,也可以通过其他修好的电脑间接相连.给出操作“O x”表示修好x,给出操作“S x y”,请 ...
- poj2236无线网络
这一题的大意:在救灾当中需要用网络,这堆人就用笔记本建了一个无线网,但是来,互相通信都是有距离限制的,一台电脑只能和距离他为d的电脑通信,然后一台电脑也可以通过几台电脑搭成线这样通信.然后就是输入每台 ...
随机推荐
- 关于scanf、getchar、getch、getche缓冲区分析——C语言
缓冲区 根据数据刷新的时机可以将缓冲区的类型分为:全缓冲.行缓冲.无缓冲 (注意:Windows下的输出设备没有缓冲区,意思是printf是无缓冲的,但是在Linux下printf就是行缓冲的,至于为 ...
- 【spring cloud】服务启动后正常,但是无法上线,一直处于down状态
spring cloud eureka 如果出现某个应用实例 down(1), 说明 spring admin 健康检测没有通过导致 eureka 注册中心不会把这个实例从列表中删除掉. 这样所有使用 ...
- FTP服务安装与端口说明
FTP服务安装与端口说明 FTP端口修改安装部署windowswindows 2012文件服务 1. FTP服务介绍 1.1 什么是FTP FTP(File Transfer Protocol)是文件 ...
- 改变IIS的Framework版本
Changing the Framework version requires a restart of the W3SVC service. Alternatively, you can chang ...
- odoo开发笔记-自定义发送邮件模板
1. 首先激活开发者模式 2. 点击设置 - Email - 模板 - “选择你需要修改的模板” 我们以销售模块-报价单 邮件模板为例 来说明. quote order 原先默认模板,发出的邮件显示效 ...
- java.io.IOException: Stream closed解决办法
1.出现这个bug的大体逻辑代码如下: private static void findMovieId() throws Exception { File resultFile = new File( ...
- php javascript comet
简单描述: comet是用ajax实现的服务器推送,有两种实现comet的方式,长轮询和流,这里只实现长轮询. 长轮询的过程:页面发起一个服务器请求,然后服务器一直保持连接打开,直到有数据返回.返回数 ...
- 解决org.apache.shiro.session.UnknownSessionException: There is no session with id的问题
一.背景 最近在整合了Spring+Shiro+Redis实现tomcat集群session共享的问题之后,发布以后运行以后发现老是会出现:org.apache.shiro.session.Unkno ...
- Disruptor入门
一.什么是 Disruptor Disruptor是一个高性能的异步处理框架,或者可以认为是最快的消息框架(轻量的JMS),也可以认为是一个观察者模式实现,或者事件-监听模式的实现,直接称disrup ...
- MySQL slave状态之Seconds_Behind_Master【转】
在MySQL的主从环境中,我们可以通过在slave上执行show slave status来查看slave的一些状态信息,其中有一个比较重要的参数Seconds_Behind_Master.那么你是否 ...