题意:

有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. ASP.NET登录控件延伸(个性化)

    既然由登录控件涉及到了Membership,那么就不得不提到用户个性化Profile对象.个性化允许为用户保存特定的个性化信息到数据库中,因此它不同于ASP.NET状态管理之处在于可以永久性保存这些信 ...

  2. Mac下使用Apache TCPMon

    Mac下使用Apache TCPMon 参考链接: TCPMon Tutorial Anyone know how to get TCPMON working on a mac? Apache TCP ...

  3. NGUI 自定义 Drag Item Script

    最近要实现一个NGUI效果. 查看了一下,NGUI有个自带 UIDragDropItem.cs 的组件进过修改后即可以实现. 下面贴上UI布局,代码: mDragDropItem.cs using U ...

  4. MYSQL注入天书之服务器(两层)架构

    Background-6 服务器(两层)架构 首先介绍一下29,30,31这三关的基本情况: 服务器端有两个部分:第一部分为tomcat为引擎的jsp型服务器,第二部分为apache为引擎的php服务 ...

  5. URAL 1517 Freedom of Choice(后缀数组,最长公共字串)

    题目 输出最长公共字串 #define maxn 200010 int wa[maxn],wb[maxn],wv[maxn],ws[maxn]; int cmp(int *r,int a,int b, ...

  6. hdu 1800 Flying to the Mars(简单模拟,string,字符串)

    题目 又来了string的基本用法 //less than 30 digits //等级长度甚至是超过了int64,所以要用字符串来模拟,然后注意去掉前导零 //最多重复的个数就是答案 //关于str ...

  7. C# Socket 入门3 UPD(转)

    今天来写一个UPD 1.服务端: using System; using System.Collections.Generic; using System.Text; using System.Net ...

  8. POJ 3710 Christmas Game

    知识储备: 解决办法(奇偶去环):   (1) 对于长度为奇数的环,去掉其中任意一个边之后,剩下的 两个链长度同奇偶,抑或之后的 SG 值不可能为奇数,所 以它的 SG 值为 1: (2) 对于长度为 ...

  9. java反射机制(基础版)

    package com.reflect; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import ja ...

  10. eclipse工程设置的问题