题目链接:http://poj.org/problem?id=2236

题目大意:城市网络由n台电脑组成,因地震全部瘫痪,现在进行修复,规定距离小于等于d的电脑修复之后是可以直接相连

进行若干操作,O a,修复编号为a的电脑,S a,b  询问a,b电脑能否联系

思路分析:并查集,只是和并条件变了,首先要已经被修复(vis数组)其次距离要小于d,并查集搞完之后

询问的时候只需要看他们是不是有着相同的根节点即可。

代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn=+;
struct node
{
double x;
double y;
};
node com[maxn];
int fa[maxn];
bool vis[maxn];
int n,d;
double dis(int i,int j)
{
return sqrt((com[i].x-com[j].x)*(com[i].x-com[j].x)+(com[i].y-com[j].y)*(com[i].y-com[j].y));
}
int root(int x)
{
return (x==fa[x])?x:fa[x]=root(fa[x]);
}
void merge(int x,int y)
{
int fx=root(x);
int fy=root(y);
if(fx==fy) return;
fa[fx]=fy;
}
int main()
{
char s[];
int a,b;
memset(vis,false,sizeof(vis));
scanf("%d%d",&n,&d);
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&com[i].x,&com[i].y);
fa[i]=i;
}
while(scanf("%s",s)!=EOF)
{
if(s[]=='O')
{
scanf("%d",&a);
vis[a]=true;
for(int i=;i<=n;i++)
{
if(dis(a,i)<=d&&vis[i]) merge(i,a);
}
}
if(s[]=='S')
{
scanf("%d%d",&a,&b);
if(root(a)==root(b))
printf("SUCCESS\n");
else printf("FAIL\n");
}
}
}

poj2236 基础并查集的更多相关文章

  1. hdu 1829 基础并查集,查同性恋

    A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  2. poj-2236 Wireless Network &&poj-1611 The Suspects && poj-2524 Ubiquitous Religions (基础并查集)

    http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由 ...

  3. 基础并查集poj2236

    An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...

  4. HDU4496 D-City【基础并查集】

    Problem Description Luxer is a really bad guy. He destroys everything he met.  One day Luxer went to ...

  5. AOJ 2170 Marked Ancestor (基础并查集)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=45522 给定一棵树的n个节点,每个节点标号在1到n之间,1是树的根节点,有如 ...

  6. POJ-2236.WireleseNetwork.(并查集)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 43199   Accepted: 178 ...

  7. CodeForces - 827A:String Reconstruction (基础并查集)

    Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...

  8. hdu1325 Is It A Tree? 基础并查集

    #include <stdio.h> #include <string.h> ], g[]; int find(int x) //并查集的查找,找到共同的父亲 { if (f[ ...

  9. HDU1213How Many Tables(基础并查集)

    HDU1213How Many Tables Problem Description Today is Ignatius' birthday. He invites a lot of friends. ...

随机推荐

  1. The app icon set named "AppIcon" did not have any applicable content.

    Develop Tools: xCode 5.1 I write a demo for app settings feature. The tutorial url is here. When I a ...

  2. 汇编-显示我放到AL中的数值

    按书上练习,有一些我看不懂. . .model flat,stdcall option casemap:none include \masmplus\include\windows.inc inclu ...

  3. 转:Redis作者谈Redis应用场景

    毫无疑问,Redis开创了一种新的数据存储思路,使用Redis,我们不用在面对功能单调的数据库时,把精力放在如何把大象放进冰箱这样的问题上,而是利用Redis灵活多变的数据结构和数据操作,为不同的大象 ...

  4. 转:Yii实战中8个必备常用的扩展,模块和widget

    转载自:http://www.yiiframework.com/wiki/180/yii8/ 在经过畅K网的实战后,总结一下在Yii的项目中会经常用到的组件和一些基本的使用方法,分享给大家,同时也给自 ...

  5. JavaScript权威指南学习笔记6

    这两天主要翻看了书中的第18-22章,重点看了第17章:事件化处理,其它几章节主要是翻了下书知道有相关的概念,没有真正理解其中的内容,或者没有考虑究竟如何能把里面的内容应用到实际的项目中.说的讽刺一点 ...

  6. win7 清理系统

    1. 先用CCleaner等第三方软件清理一下.2. 将用户文件.我的文档.我的音乐.我的视频.桌面等路径更改到非系统分区(文件也会一并移动过去)3. 将系统盘的系统还原占用空间比减小,将大部分虚拟内 ...

  7. Delphi String 与wideString 的完美转换

    一般来说,String与widestring 的转换是系统自动进行的,但是,考虑如下字符串 s:=#2+#3+#0+#10+#0+#1+#164+#59;,显然S的长度为8,然后执行如下代码 var ...

  8. 前端问题——png图片在IE6下透明失效,解决办法

    今天,一位同事问我问题,png 图片在IE6下透明背景失效. 解决办法,在网上查了很多,最后还是采用两种方案来解决这个问题 1.把这个网页的png格式图片变更为gif格式的图片.问题解决 2.就是让这 ...

  9. POJ 1700 坐船过河问题

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82974#problem/E 解题思路:当n>=4,假设n个人单独过河所需 ...

  10. MARCHdesign_王濤's 星云个人网站 | www.xingyun.cn/MARCHdesign

    MARCHdesign_王濤's 星云个人网站 | www.xingyun.cn/MARCHdesign MARCHdesign_王濤