POJ-2236.WireleseNetwork.(并查集)
Wireless Network
| Time Limit: 10000MS | Memory Limit: 65536K | |
| Total Submissions: 43199 | Accepted: 17800 |
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
#include <cstdio>
#include <cmath>
using namespace std; const int maxn = + ;
struct coordinate {
int x, y;
} G[maxn];
int n, d, p, q, cnt, head[maxn], Rank[maxn];
int isrepair[maxn];
char operation; double dis(int u, int v) {
return sqrt((double)(G[u].x - G[v].x) * (G[u].x - G[v].x) + (G[u].y - G[v].y) * (G[u].y - G[v].y));
} int find(int x) {
if(head[x] == x) return x;
return head[x] = find(head[x]);
} void Union_set(int x, int y) {
int dx = find(x), dy = find(y);
if(dx == dy) return;
if(Rank[dx] > Rank[dy]) head[dx] = dy;
else {
head[dy] = dx;
if(Rank[dx] == Rank[dy])
Rank[dx] ++;
}
} bool Is_same(int u, int v) {
return find(u) == find(v);
} int main () {
cnt = ;
scanf("%d %d", &n, &d);
for(int i = ; i <= n; i ++)
scanf("%d %d", &G[i].x, &G[i].y);
for(int i = ; i <= n; i ++) {
head[i] = i;
Rank[i] = ;
}
while(~scanf("%c", &operation)) {
if(operation == 'O') {
scanf("%d", &p);
for(int i = ; i <= cnt; i ++) {
if(dis(p, isrepair[i]) <= d) {
Union_set(isrepair[i], p);
}
}
isrepair[cnt ++] = p;
}
else if(operation == 'S') {
scanf("%d %d", &p, &q);
if(Is_same(p, q))
printf("SUCCESS\n");
else
printf("FAIL\n");
}
}
return ;
}
POJ-2236.WireleseNetwork.(并查集)的更多相关文章
- poj 2236【并查集】
poj 2236 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical t ...
- Poj(2236),简单并查集
题目链接:http://poj.org/problem?id=2236 思路很简单,傻逼的我输出写成了FALL,然后遍历的时候for循环写错了,还好很快我就Debug出来了. #include < ...
- POJ 2236 (简单并查集) Wireless Network
题意: 有n个电脑坏掉了,分别给出他们的坐标 有两种操作,可以O x表示修好第x台电脑,可以 S x y表示x y是否连通 两台电脑的距离不超过d便可连通,两台电脑是连通的可以直接连通也可以间接通过第 ...
- poj 2524 (并查集)
http://poj.org/problem?id=2524 题意:在一所学校里面的人,都有宗教信仰,不过他们的宗教信仰有可能相同有可能不同,但你又不能直接去问他们,但你可以问他们和谁是同一个宗教.通 ...
- [POJ 2588]--Snakes(并查集)
题目链接:http://poj.org/problem?id=2588 Snakes Time Limit: 1000MS Memory Limit: 65536K Description B ...
- poj 1456 Supermarket - 并查集 - 贪心
题目传送门 传送点I 传送点II 题目大意 有$n$个商品可以销售.每个商品销售会获得一个利润,但也有一个时间限制.每个商品需要1天的时间销售,一天也只能销售一件商品.问最大获利. 考虑将出售每个物品 ...
- poj 2492(关系并查集) 同性恋
题目;http://poj.org/problem?id=2492 卧槽很前卫的题意啊,感觉节操都碎了, t组测试数据,然后n,m,n条虫子,然后m行,每行两个数代表a和b有性行为(默认既然能这样就代 ...
- poj 1182 (关系并查集) 食物链
题目传送门:http://poj.org/problem?id=1182 这是一道关系型并查集的题,对于每个动物来说,只有三种情况:同类,吃与被吃: 所以可以用0,1,2三个数字代表三种情况,在使用并 ...
- Poj(1182),种类并查集
题目链接:http://poj.org/problem?id=1182 再次熟练种类并查集,又积累点经验,和技巧,rank 0 2 1 先计算father[x] ,再更新rank[x]; #inclu ...
随机推荐
- 廖雪峰Java9正则表达式-2正则表达式进阶-3分组匹配
1.使用括号可以提取字符串 不加括号匹配电话号码 匹配成功后,如何提取想要的字符串? 使用(...)可以分组:"^(\d{3,4})\-(\d{6,8})$" 2.String.m ...
- Docker使用Link与newwork在容器之间建立连接
一,使用 --link容器互联 docker 默认使允许container 互通的(通过-icc=false 关闭互通)同一个宿主机上的多个docker容器之间如果想进行通信,可以通过使用容器的ip地 ...
- netmap配置
1.配置流程 环境:centos 7.2.1511,内核版本3.10.0-327.el7.x86_64 [1]下载内核源码,https://buildlogs.cdn.centos.org/c7.15 ...
- Kafka安装及开启SASL_PLAINTEXT认证(用户名和密码认证)
前些日子要封装一个kafka的客户端驱动,配置了下kafka环境,发现配置复杂度完爆rabbitmq很多倍啊,而且发布订阅模式使用起来也很麻烦,可能就胜在分布式了吧. kafka需要java环境,自行 ...
- Microsoft Speaker Recognition API
azure说话人识别API 官方文档:https://westus.dev.cognitive.microsoft.com/docs/services/563309b6778daf02acc0a508 ...
- SN Writer 写号工具使用
SN Writer 写号工具的使用 蓝牙写号: 打开SN Writer 写号工具 1.点击System Config按钮 2.进入界面,选择需要写号的类型,及选择相应的写号文件, ...
- Vue 路由的嵌套
1.配置路由 const routes = [ { path: '/User', component: User, children: [{ path: 'OP1', component: OP1 } ...
- IntelliJ IDEA 破解Jrebel6.3.0安装
首先下载所必要的两个文件(jrebel3.6.0和cracked文件) 密码:pvsd 注意:如果不是该版本的Jrebel该破解文件可能无效. 步骤1:安装 解压文件得出两个压缩包 在idea中选择 ...
- 为什么你需要少看垃圾博客以及如何在Python里精确地四舍五入
今天又有一个Python初学者被中文技术博客中的垃圾文章给误导了. 这位初学者的问题是: 在Python中,如何精确地进行浮点数的四舍五入,保留两位小数? 如果你在Google或者百度上搜索,你会发现 ...
- java面试题复习(三)
21.静态嵌套类和内部类的不同? 答:静态嵌套类是被声明为静态(static)的内部类,它可以不依赖于外部类实例被实例化.而通常的内部类需要在外部类实例化后才能实例化.//还是考的static的知识 ...