题目链接: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. C语言:Message类

    message.h #ifndef MESSAGE_H #define MESSAGE_H #define TRUE 1 #define FALSE 0 typedef struct { int se ...

  2. poj 2488A Knight's Journey

    #include<cstdio> #include<cstring> #define MAXN 26 using namespace std; ,,-,,-,,-,}; ,-, ...

  3. activitie5 流程入门例子

    流程这个东西在ERP项目用得比较多.在网上找到一个例子,与大家分享一下.http://yiyiboy2010.iteye.com/blog/1530924 感谢原博主提供 http://blog.ch ...

  4. treap修订

    #include<cstdio> #include<cmath> #include<algorithm> #include<ctime> #includ ...

  5. python队列join

    如果要让一个任务队列按照顺序进行,则必须使用join,代码如下: ''' Created on Dec 23, 2013 @author: long ''' import threading from ...

  6. XML初学笔记

    一.基本概要: XML,全称是eXtensible Markup Language,可扩展的标记语言,是Web服务的基础之一,使用XML,用户可以定义自己需要的标记.而用户创建的标记可以使用文档类型定 ...

  7. Selenium webdriver 元素操作

    本来这些东西网上一搜一大堆,但是本着收集的精神,整理一份放着吧!哈!哈!哈! 1. 输入框(text field or textarea) WebElement element = driver.fi ...

  8. JVM之--Java内存结构(第一篇)

    最近在和同事朋友聊天的时候,发现一个很让人思考的问题,很多人总觉得JVM将java和操作系统隔离开来,导致很多人不用熟悉操作系统,甚至不用了解JVM本身即可完全掌握Java这一门技术,其实个人的观点是 ...

  9. java笔记9之switch

    switch语句的注意事项:        A:case后面只能是常量,不能是变量,而且,多个case后面的值不能出现相同的        B:default可以省略吗?            可以省 ...

  10. driver.startActivity 启动app出现 An unknown server-side error occurred while processing the command

    driver.startActivity("com.xxx.module.xxx", "com.xxx.module.xxx.hibox.ui.entry.EntryAc ...