题意:

有n个电脑坏掉了,分别给出他们的坐标

有两种操作,可以O x表示修好第x台电脑,可以 S x y表示x y是否连通

两台电脑的距离不超过d便可连通,两台电脑是连通的可以直接连通也可以间接通过第三台电脑连通

思路:

每次修好一台电脑都和前面已经修好的电脑比较一下如果距离小于d而且不在同一网络,便合并在一起即可

 //#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int maxn = + ;
struct Pos
{
int x, y;
}pos[maxn]; int p[maxn], o[maxn]; int Find(int a)
{
return p[a] == a ? a : p[a] = Find(p[a]);
} void Union(int a, int b)
{
int pa = Find(a);
int pb = Find(b);
if(pa != pb)
p[pa] = pb;
} int main(void)
{
#ifdef LOCAL
freopen("2236in.txt", "r", stdin);
#endif int n, d, a, b, cnt = ;
char cmd[];
scanf("%d%d", &n, &d);
for(int i = ; i <= n; ++i) p[i] = i;
memset(o, false, sizeof(o));
for(int i = ; i <= n; ++i)
scanf("%d%d", &pos[i].x, &pos[i].y);
while(scanf("%s", cmd) != EOF)
{
if(cmd[] == 'O')
{
scanf("%d", &a);
o[cnt++] = a;
for(int i = ; i < cnt - ; ++i)
{
if((pos[a].x-pos[o[i]].x)*(pos[a].x-pos[o[i]].x) + (pos[a].y-pos[o[i]].y)*(pos[a].y-pos[o[i]].y) <= d * d)
{
Union(a, o[i]);
}
}
}
else
{
scanf("%d%d", &a, &b);
if(Find(a) == Find(b))
puts("SUCCESS");
else
puts("FAIL");
}
} return ;
}

代码君

POJ 2236 (简单并查集) Wireless Network的更多相关文章

  1. Poj(2236),简单并查集

    题目链接:http://poj.org/problem?id=2236 思路很简单,傻逼的我输出写成了FALL,然后遍历的时候for循环写错了,还好很快我就Debug出来了. #include < ...

  2. POJ 2524 (简单并查集) Ubiquitous Religions

    题意:有编号为1到n的学生,然后有m组调查,每组调查中有a和b,表示该两个学生有同样的宗教信仰,问最多有多少种不同的宗教信仰 简单并查集 //#define LOCAL #include <io ...

  3. poj 2236【并查集】

    poj 2236 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical t ...

  4. POJ 2492 (简单并查集) A Bug's Life

    题意:有编号为1~n的虫子,开始假设这种昆虫是异性恋.然后已知xi 和 yi进行交配,根据已知情况分析能否推理出其中是否有同性恋 这道题和 POJ 1182 食物链 十分相似,不过在更新与父节点关系的 ...

  5. poj 1611 简单并查集的应用

    #include<stdio.h> #define N 31000 int pre[N]; int find(int x) { if(x!=pre[x])     pre[x]=find( ...

  6. poj1611 简单并查集

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 32781   Accepted: 15902 De ...

  7. 1213 How Many Tables(简单并查集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 简单并查集,统计单独成树的数量. 代码: #include <stdio.h> #i ...

  8. 【简单并查集】Farm Irrigation

    Farm Irrigation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tot ...

  9. ACM_“打老虎”的背后(简单并查集)

    “打老虎”的背后 Time Limit: 2000/1000ms (Java/Others) Problem Description: “习大大”自担任国家主席以来大力反腐倡廉,各地打击贪腐力度也逐步 ...

随机推荐

  1. jQuery1.9.1--queue队列源码分析(非动画部分)

    jQuery.extend({ // 显示或操作在匹配元素上执行的函数队列 queue: function (elem, type, data) { var queue; if (elem) { // ...

  2. ZOJ3229 Shoot the Bullet(有源汇的上下界最大流)

    #pragma warning(disable:4996) #include <iostream> #include <cstring> #include <string ...

  3. root 授权

    错误:The user specified as a definer ('root'@'%') does not exist 解决: grant all privileges on *.* to ro ...

  4. (7)nehe教程1 创建一个OpenGL窗口:

    不要用那个nehe ndk了 误人子弟! 转自: 一个窗口,代码可真多啊 http://www.yakergong.net/nehe/ 在这个教程里,我将教你在Windows环境中创建OpenGL程序 ...

  5. Java 动态代理机制分析及扩展

    Java 动态代理机制分析及扩展,第 1 部分 王 忠平, 软件工程师, IBM 何 平, 软件工程师, IBM 简介: 本文通过分析 Java 动态代理的机制和特点,解读动态代理类的源代码,并且模拟 ...

  6. 正则表达式(RegExp)

    正则表达式(RegExp) 如何按一定规则快速查找到需要找寻的内容,js的设计者们给我们提供了一个叫正则表达式(RegExp对象),专门用于处理类似问题. RegExp对象表示正则表达式,它是对字符串 ...

  7. eclipse引入tomcat

    1.默认大家的tomcat都已经安装好了,这里打开eclipse,选择windows,下面的属性(preference). 2.进入到属性配置页,选择server  --   runtime Envi ...

  8. linux系统下挂载windows共享目录

    在工作中有时我们需要在linux上挂载windows共享目录.首先我们需要学会在linux上查看windows共享了那些目录.查看操作需要安装samba-client. [root@ ~]# yum ...

  9. C#DataGrdviewl加入checkBox全选删除

    #region 加入checkBox /// <summary> /// 加入checkBox /// </summary> /// <param name=" ...

  10. 关于SIGPIPE导致的程序退出

    http://www.cppblog.com/elva/archive/2008/09/10/61544.html 收集一些网上的资料,以便参考: http://blog.chinaunix.net/ ...