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 ...
随机推荐
- Nodejs基础:路径处理模块path总结
模块概览 在nodejs中,path是个使用频率很高,但却让人又爱又恨的模块.部分因为文档说的不够清晰,部分因为接口的平台差异性. 将path的接口按照用途归类,仔细琢磨琢磨,也就没那么费解了. 获取 ...
- Code First操作Mysql数据库
前面博客也讲了,自己做一个网站,选用的是MVC+EF Code First+MySql+EasyUI,先说下技术选型.一.为什么选择MVC? 因为之前自己做的系统大部分是webForm,MVC的之前也 ...
- 准确率(Accuracy), 精确率(Precision), 召回率(Recall)和F1-Measure
yu Code 15 Comments 机器学习(ML),自然语言处理(NLP),信息检索(IR)等领域,评估(Evaluation)是一个必要的 工作,而其评价指标往往有如下几点:准确率(Accu ...
- 当在XP系统上无法安装Mysql ODBC时,怎么办?
system32下面缺失如下连接中的dll http://www.33lc.com/soft/19950.html 这个dll名为: msvcr100.dll 本来安装过程中会出现Error 1918 ...
- git--- 拉取代码
- PHP中错误处理集合
PHP错误处理 错误的分类 通常分3种: 语法错误: 程序运行之前,都要先检查语法.如果语法有错误,就会立即报错,并且不会去执行程序. 运行时错误: 就是在程序语法检查通过后,,开始运行程序并在此过程 ...
- 【HDU 2089】不要62
http://acm.hdu.edu.cn/showproblem.php?pid=2089 数位dp,参照了打野的博客 预处理出f数组,f[i][j]表示第i位为数字j时的可行的数字总数. 对于区间 ...
- 美化select下拉框
直接上干货: 需要的材料: change_select.js (文末会给出下载地址) 使用方法: 1.调用方法:<script type="text/javascript" ...
- JS 打印功能代码可实现打印预览、打印设置等
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or ...
- block的使用
转载自:http://mobile.51cto.com/hot-403897.htm 一.概述 Block是C级别的语法和运行时特性.Block比较类似C函数,但是Block比之C函数,其灵活性体现在 ...