网址:http://poj.org/problem?id=2236

题意:有n台坏的电脑,如果每两台电脑的距离不能超过d,那么这两台电脑有联系,用字符串O 表示标记第x台电脑维修了,用S判断从X到y是否有联系。。。

题解:用并查集记录和查找每个点的父亲节点,每次输入的同时遍历该点和其他点是否有联系(即距离小于等于的)。。。。。

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
struct point
{
int x,y;
int pre;
bool k;
}p[];
void New(int n)
{
for(int i=; i<=n; i++)
{
p[i].pre=i;
}
}
int find(int x)
{
if(p[x].pre!=x)
{
p[x].pre=find(p[x].pre);
}
return p[x].pre;
//return x == p[x].pre ? x : find(p[x].pre);
}
int dis(point p1,point p2)
{
return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
}
void Union(point p1,point p2,int d)
{
int root1=find(p1.pre);
int root2=find(p2.pre);
if(root1 != root2)
{
if( dis(p1,p2) <= d * d )
{
p[root2].pre = root1;
}
}
}
int main()
{
char s;
int n , d;
scanf( "%d%d", &n ,&d);
New(n);
for(int i = ; i <= n; i++)
{
scanf( "%d%d", &p[i].x , &p[i].y);
}
while(~scanf("\n%c", &s))
{
int r , a, b;
if(s=='O')
{
scanf("%d", &r);
p[r].k=;
for(int i = ; i <= n; i++)
if(p[i].k && i != r)
Union(p[i] , p[r],d);
}
else
{
scanf("%d%d", &a, &b);
if(find(a) == find(b))
printf("SUCCESS\n");
else
printf("FAIL\n");
}
}
}

并查集 poj2236的更多相关文章

  1. 基础并查集poj2236

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

  2. 并查集——poj2236(带权并查集)

    题目:Wireless Network 题意:给定n台已损坏计算机的位置和计算机最远通信距离d,然后分别根据命令执行以下两种操作: "O p" (1 <= p <= N ...

  3. poj2236(并查集)

    题目链接: http://poj.org/problem?id=2236 题意: 有n台计算机, 已知每台计算机的坐标, 初始时所有计算机都是坏的, 然后修复其中一些计算机, 已修复的计算机距离不超过 ...

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

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

  5. poj2236 基础并查集

    题目链接:http://poj.org/problem?id=2236 题目大意:城市网络由n台电脑组成,因地震全部瘫痪,现在进行修复,规定距离小于等于d的电脑修复之后是可以直接相连 进行若干操作,O ...

  6. POJ2236 Wireless Network 并查集简单应用

    Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...

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

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

  8. poj2236 Wireless Network(并查集直接套模板

    题目地址:http://poj.org/problem?id=2236 题目大意:n台电脑都坏了,只有距离小于d且被修好的电脑才可以互相联系,联系可传递.输入n和d,n个点的坐标x y.两个操作:O ...

  9. 《挑战程序设计竞赛》2.4 数据结构-并查集 POJ1182 2236 1703 AOJ2170

    POJ1182 http://poj.org/problem?id=1182 题目 难得的中文题... 食物链 Time Limit: 1000MS Memory Limit: 10000K Tota ...

随机推荐

  1. Unable to the boot Simulator ! Mac开机现“CoreTelephony Trace File Error”,

    OS X升级到El Capitan之后,提供一个跟安全相关的模式叫SIP(System Integrity Protection),又称rootless mode,这个新功能在強化OS X的安全性,它 ...

  2. C++之路进阶——HDU1880(魔咒词典)

    ---恢复内容开始--- New~ 欢迎参加2016多校联合训练的同学们~ 魔咒词典 Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 3 ...

  3. 。。。欢乐捕鱼App WeX5 连接打包代理服务失败,请检查代理服务地址是否正确。。。

    今天学习了WeX5,第一次使用,使用它打包一个Web App 欢乐捕鱼的时候,在最终打包生成Native App的时候突然报错了,说:"连接打包代理服务失败,请检查代理服务地址是否正确&qu ...

  4. AppSettings从数据库读取

    /// <summary> /// 提供对配置信息的访问 /// </summary> public static class AppSettings { /// <su ...

  5. JS SDK 随手笔记

    JS SDK 随手笔记 窗口模块 Frame/Multi Frame 对话框 页面间的通讯 生命周期 窗口层叠 窗口模块 窗口模块是是AppCan移动应用界面最基本的单位.窗口是每个界面布局的基础,他 ...

  6. C#动态生成html页

    Html生成模块:WriteHtml.cs using System.Collections.Generic; using System.IO; using System.Text; namespac ...

  7. Asp.net mvc 添加Jquery UI

    1.使用NuGet下载jquery ui Install-Package jQuery.UI.Combined 2.下载多语言文件: development-bundle/i18n目录下是jquery ...

  8. python学习笔记之基础二(第二天)

    1.编码转换介绍        unicode是最底层.最纯的,会根据终端的编码进行转化展示 一般硬盘存储或传输为utf-8(因为省空间.省带宽),读入内存中为unicode,二者如何转换 a = ' ...

  9. python 学习(二)--关于类

    1.没有权限控制,在类方法或变量前加 "__" 两下划线,则变为"私有"变量(实际通过_<类名>__<变量或方法名> 可以访问) 2.类 ...

  10. Dynamics AX 2012 R2 AIF No Endpoint Behavior Named 'clientEndpointBehavior'

          最近,Reinhard在使用Http Adapter类型的AIF入站端口时,总是报以下错误: Server Error in '/MicrosoftDynamicsAXAif60' App ...