题意:

有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. jQuery中的Deferred-详解和使用

    首先,为什么要使用Deferred? 先来看一段AJAX的代码: var data; $.get('api/data', function(resp) { data = resp.data; }); ...

  2. c#比较器 排序

    原地址:http://blog.csdn.net/xutao_ustc/article/details/6314057 class Program { static void Main(string[ ...

  3. ExtJs布局之tabPanel

    <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...

  4. WCF分布式开发步步为赢(4):WCF服务可靠性传输配置与编程开发

    今天继续WCF分布式开发步步为赢系列的第4节:WCF服务可靠性传输配置与编程开发.这个章节,我们要介绍什么是WCF服务的可靠性传输,随便介绍网络协议的概念,Web Service为什么不支持可靠性传出 ...

  5. struct 理解 (需要经常理解)

    2014.3.11 分析offviewer时,有一些问题,很基础的,但是忘记了,发现问题那就快点搞定它 以下内容参考自百度百科: (2)struct 结构体有点忘记了,要复习一下  定义一个结构的一般 ...

  6. poj 2449(A*求第K短路)

    题目链接:http://poj.org/problem?id=2449 思路:我们可以定义g[x]为源点到当前点的距离,h[x]为当前点到目标节点的最短距离,显然有h[x]<=h*[x](h*[ ...

  7. C#DataGridView 美化

    private void dataGridView(DataGridView dataGridView) { System.Windows.Forms.DataGridViewCellStyle da ...

  8. jquery.lazyload用法

    lazyload是jquery的插件,作为延迟加载图片,减压服务器压力. 如何使用: 先把 <script src="jquery.js" type="text/j ...

  9. C# 访问USB(HID)设备

    原文:C# 访问USB(HID)设备 二话不说,直接给代码,如果您真想做这方面的东西,还是稍微研究下,没有现成的好类用,就需要自己了解其原理 //引用空间 using System; using Sy ...

  10. 301. Remove Invalid Parentheses

    题目: Remove the minimum number of invalid parentheses in order to make the input string valid. Return ...