Wireless Network(并查集)
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std; int n,d;
char c;
int p,q;
int book[]={},f[]; //分别是 标记是否修好 , 找爸 struct note
{
int x,y;
}a[]; //记录坐标 int getf(int u)
{
return u==f[u]? u:getf(f[u]);
} void merge(int x,int y)
{
x=getf(x);
y=getf(y);
if(x!=y)
{
f[y]=x;
}
} int main()
{
cin>>n>>d;
for(int i=;i<=n;i++)
{
f[i]=i;
cin>>a[i].x>>a[i].y;
}
while(cin>>c)
{
if(c=='O') //修
{
cin>>p;
book[p]=; //修好了 ,下面进行寻找
for(int i=;i<=n;i++)
{
//第i个电脑不和第p的电脑超出距离,并且第i个电脑已经被修好 是能连通的基本条件
if( d*d >= 1.0*((a[p].x-a[i].x)*(a[p].x-a[i].x)+(a[p].y-a[i].y)*(a[p].y-a[i].y)) && book[i]==)
merge(f[p],f[i]); //这里左右位置不要变,要一直都把电脑p作为爸爸
}
}
else if(c=='S')
{
cin>>p>>q;
if(getf(p)==getf(q))
cout<<"SUCCESS"<<endl;
else
cout<<"FAIL"<<endl;
}
}
}
Wireless Network(并查集)的更多相关文章
- POJ 2236 Wireless Network (并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 18066 Accepted: 761 ...
- POJ2236 Wireless Network 并查集简单应用
Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...
- Wireless Network 并查集
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- poj 2236 Wireless Network (并查集)
链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...
- POJ 2236 Wireless Network [并查集+几何坐标 ]
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- POJ2236 Wireless Network 并查集
水题 #include<cstdio> #include<cstring> #include<queue> #include<set> #include ...
- [LA] 3027 - Corporative Network [并查集]
A very big corporation is developing its corporative network. In the beginning each of the N enterpr ...
- LA 3027 Corporative Network 并查集记录点到根的距离
Corporative Network Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [S ...
- UVALive - 3027 Corporative Network (并查集)
这题比较简单,注意路径压缩即可. AC代码 //#define LOCAL #include <stdio.h> #include <algorithm> using name ...
- 【转】并查集&MST题集
转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基 ...
随机推荐
- 【MM系列】SAP 采购订单收货后不能修改价格的增强
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP 采购订单收货后不能修改价格的 ...
- 【ARM-Linux开发】Linux查看设备驱动
驱动操作命令: insmod / modprobe 加载驱动 rmmod 卸载驱动 lsmod 查看系统中所有已经被 ...
- 自定义Hive函数
7. 函数 7.1 系统内置函数 查看系统自带的函数:show functions; 显示自带的函数的用法:desc function upper(函数名); 详细显示自带的函数的用法:desc fu ...
- Django与JS交互的示例代码-django js 获取 python 字典-Django 前后台的数据传递
Django与JS交互的示例代码 Django 前后台的数据传递 https://www.cnblogs.com/xibuhaohao/p/10192052.html 应用一:有时候我们想把一个 li ...
- PCL学习(三) SAC-IA 估记object pose
SAC-IA是基于RANSAC算法的对齐算法 通过降采样提高法向计算.FPFH特征的计算 最后通过SAC-IA计算得到对齐的旋转和平移 #include <Eigen/Core> #inc ...
- hadoop WordCount例子详解。
[学习笔记] 下载hadoop-2.7.4-src.tar.gz,拷贝hadoop-2.7.4-src.tar.gz中hadoop-mapreduce-project\hadoop-mapreduce ...
- C/C++内存知识(一)
一.C/C++编译的程序占用的内存分为以下几个部分 1.栈区(stack)- 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等.其操作方式类似于数据结构中的栈. 2.堆区(heap)- 由程序 ...
- C++ algorithm算法库
C++ algorithm算法库 Xun 标准模板库(STL)中定义了很多的常用算法,这些算法主要定义在<algorithm>中.编程时,只需要在文件中加入#include<algo ...
- Python print函数详解
1 """ 2 print(...) 3 print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=Fals ...
- PyCharm 2018.3.3激活(亲测有效)
转自:简书某大佬 https://www.jianshu.com/p/351dee5d7e54 附截图: