POJ 2236 Wireless Network(并查集)
Wireless Network
| Time Limit: 10000MS | Memory Limit: 65536K | |
| Total Submissions: 24513 | Accepted: 10227 |
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
思路
#include<stdio.h>
#include<string.h>
const int maxn = 1005;
struct Node{
int x,y;
}node[maxn];
int N,d,fa[maxn];
bool repair[maxn];
int find(int x)
{
int r = x;
while (r != fa[r]) r = fa[r];
int i = x,j;
while (i != r)
{
j = fa[i];
fa[i] = r;
i = j;
}
return r;
}
void unite(int x,int y)
{
x = find(x),y = find(y);
if (x != y) fa[x] = y;
}
bool dist(struct Node xx,struct Node yy)
{
return ((xx.x-yy.x)*(xx.x-yy.x)+(xx.y-yy.y)*(xx.y-yy.y)) <= d*d;
}
int main()
{
int index,index1,index2;
char op[5];
memset(repair,false,sizeof(repair));
scanf("%d%d",&N,&d);
for (int i = 1;i <= N;i++)
{
fa[i] = i;
scanf("%d%d",&node[i].x,&node[i].y);
}
while (~scanf("%s",op))
{
if (op[0] == 'O')
{
scanf("%d",&index);
repair[index] = true;
for (int i = 1;i <= N;i++)
{
if (i != index && repair[i] && dist(node[i],node[index])) unite(i,index);
}
}
else if (op[0] == 'S')
{
scanf("%d%d",&index1,&index2);
index1 = find(index1),index2 = find(index2);
if (index1 == index2) printf("SUCCESS\n");
else printf("FAIL\n");
}
}
return 0;
}
POJ 2236 Wireless Network(并查集)的更多相关文章
- POJ 2236 Wireless Network (并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 18066 Accepted: 761 ...
- poj 2236 Wireless Network (并查集)
链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...
- POJ 2236 Wireless Network [并查集+几何坐标 ]
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集
POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...
- [并查集] POJ 2236 Wireless Network
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 25022 Accepted: 103 ...
- poj 2236:Wireless Network(并查集,提高题)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 16065 Accepted: 677 ...
- POJ 2236 Wireless Network (并查集)
Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...
- [ An Ac a Day ^_^ ] [kuangbin带你飞]专题五 并查集 POJ 2236 Wireless Network
题意: 一次地震震坏了所有网点 现在开始修复它们 有N个点 距离为d的网点可以进行通信 O p 代表p点已经修复 S p q 代表询问p q之间是否能够通信 思路: 基础并查集 每次修复一个点重新 ...
- poj 2236 Wireless Network 【并查集】
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 16832 Accepted: 706 ...
随机推荐
- 分析cocos2d-x中的CrystalCraze示例游戏
cocos2d-x自带了不少示例,以及几个比较简单的游戏,不过这些游戏都是用javascript binding(SpiderMonkey)做的,所以我猜测javascript binding可能是c ...
- 学习SQLite之路(一)
工作快一年了,接触的东西不是很多,学到的东西也不多.无意中看到公司的代码有一点关于sqlite3的(不是我这一层负责的代码),于是乎就学学试试. 参考: http://www.runoob.com/s ...
- hystrix-turbine 监控的使用
1. 概述 Demo地址:http://git.oschina.net/zhou666/spring-cloud-7simple/tree/master/cloud-hystrix-turbine ...
- OS存储器管理(二)
离散分配 分页(Paging),分段,段页式 一.分页 一个进程的物理地址可以是非连续的: 将物理内存分成固定大小的块,称为块(frame): 将逻辑内存分为同样大小的块,称为页(page): ...
- [BZOJ2152]聪聪可可(点分治)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2152 分析:裸的点分治,对于每课树,记录t[0],t[1],t[2]表示到当前根节点距 ...
- JavaScript的理解记录(4)
客户端JavaScript:客户端就是Web浏览器; 一. 前奏: Web文档(document):一些呈现静态信息的页面,虽然有的页面是会动的,但信息本身还是静态! Web应用:可以动态载入信息,相 ...
- Ubuntu disk error
I have heard that ext file system is easy to crash. Today i forced to shutdown Ubuntu. As a result,i ...
- Bete冲刺第二阶段
Bete冲刺第二阶段 今日工作: web: 修复了a版本中接口数据返回错误的问题.通知对数据表新增了几个字段.并且新增了一个通知查询的接口. ios: 修正网络连接bug 招募功能界面完成但是跳转问题 ...
- 1109关于redo_Log和undo_log和BIN-LOG
转自http://www.cnblogs.com/Bozh/archive/2013/03/18/2966494.html 三者之间的区别BIN-LOG 一个对应BINLOG文件REDO-LOG 对应 ...
- 1031MVCC和事务浅析
转自 http://blog.csdn.net/sofia1217/article/details/50778906 关于MVCC浅析,有些难度http://xuebinbin212.blog.163 ...