POJ 2236 Wireless Network

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

题目大意:

给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y均能C通信,则x和y可以通信。现在给出若干个操作,

O p 代表修复编号为p的电脑

S p q代表询问p和q是不是能通信。

思路:

并查集即可。。

如果修复了一台电脑,则把与它相连距离不超过d的且修复了的放在一个集合里面。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=1000+10;
int fa[MAXN],n,d;
bool canuse[MAXN];
int find(int cur)
{
return fa[cur]<0? cur: fa[cur]=find(fa[cur]);
}
struct computers
{
int x,y;
}a[MAXN];
bool ok(int x1,int y1,int x2,int y2)
{
return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2) <= d*d;
}
int main()
{
memset(fa,-1,sizeof(fa));
memset(canuse,0,sizeof(canuse)); scanf("%d%d",&n,&d);
for(int i=1;i<=n;i++)
scanf("%d%d",&a[i].x,&a[i].y); char cmd[10];
int p,q;
while(~scanf("%s",cmd))
{
if(cmd[0]=='O')
{
scanf("%d",&p);
int root=find(p);
for(int i=1;i<=n;i++)
{
if(i==p) continue;
if(ok(a[i].x,a[i].y,a[p].x,a[p].y) && canuse[i])
{
int root1=find(i);
int root2=find(p);
if(root1!=root2)
fa[root1]=root2;
}
}
canuse[p]=true;
}
else
{
scanf("%d%d",&p,&q);
int rootp=find(p);
int rootq=find(q);
if(rootp==rootq)
printf("SUCCESS\n");
else
printf("FAIL\n");
}
}
return 0;
}

POJ 1703 Find them, Catch them

http://poj.org/problem?id=1703

题目大意:

xx城市有两个帮派,给你m条信息,D a b表示a和b不在一个帮派里。A a b时要求输出a和b是不是在一个帮派里。(在/不在/不确定)

思路:

和这题POJ 1182 食物链 并查集差不多。

划分为两个集合,给出D a b 说明a和b不在一个集合,那么就合并a和b+n,b和a+n。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=200000+10;
int fa[MAXN];
int find(int cur)
{
return cur==fa[cur]? cur: fa[cur]=find(fa[cur]);
}
void union_set(int a,int b)
{
int root_a=find(a);
int root_b=find(b);
if(root_a==root_b)
return;
fa[root_a]=root_b;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d%d",&n,&m);
int num=n*2;
for(int i=1;i<=num;i++)
fa[i]=i; char cmd[5];
int a,b;
for(int i=0;i<m;i++)
{
scanf("%s %d%d",cmd,&a,&b);
if(cmd[0]=='A')
{
if(find(a)==find(b))
printf("In the same gang.\n");
else if(find(a)==find(b+n) || find(b)==find(a+n))
printf("In different gangs.\n");
else
printf("Not sure yet.\n");
}
else
{
union_set(a,b+n);
union_set(a+n,b);
}
}
}
return 0;
}

POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集的更多相关文章

  1. [并查集] POJ 2236 Wireless Network

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 25022   Accepted: 103 ...

  2. poj 2236:Wireless Network(并查集,提高题)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 677 ...

  3. poj 2236 Wireless Network (并查集)

    链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...

  4. POJ 2236 Wireless Network(并查集)

    传送门  Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 24513   Accepted ...

  5. POJ 2236 Wireless Network (并查集)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 18066   Accepted: 761 ...

  6. POJ 2236 Wireless Network (并查集)

    Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...

  7. poj 2236 Wireless Network 【并查集】

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16832   Accepted: 706 ...

  8. POJ 2236 Wireless Network [并查集+几何坐标 ]

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

  9. [ An Ac a Day ^_^ ] [kuangbin带你飞]专题五 并查集 POJ 2236 Wireless Network

    题意: 一次地震震坏了所有网点 现在开始修复它们 有N个点 距离为d的网点可以进行通信 O p   代表p点已经修复 S p q 代表询问p q之间是否能够通信 思路: 基础并查集 每次修复一个点重新 ...

随机推荐

  1. SpringBoot 整合 Mybatis 和 Mysql (详细版)

    结构如下 1.引入相关依赖 <!--mysql--><dependency> <groupId>mysql</groupId> <artifact ...

  2. 【Uva 1625】Color Length

    [Link]: [Description] 给你两个序列,都由大写字母组成; 每次,把两个序列中的一个的开头字母加在字符串的尾端,然后在那个序列中删掉那个开头字母; 最后得到一个字符串; 这个字符串显 ...

  3. Linux下安装Go环境

    登录Linux Mac或Linux的用户可以用命令ssh root@xxx.xxx.xxx.xxx登录主机Window的用户可以使用SecureCRT登录主机虚拟机用户直接打开你的虚拟机 安装Go环境 ...

  4. VTK的安装配置-使用VS2010

    1.CMake的安装 CMake安装是用来对VTK编译前的配置工作.此博客中使用的是CMake2.8.CMake的下载可到https://cmake.org/站点上进行下载. 2.VTK源代码 VTK ...

  5. InnoDB引擎索引大观

    InnoDB是mysql处理OLTP(online transcation process)类型业务的存储引擎.为了加快数据查询速度.InnoDB引擎提供了丰富的索引实现. 1. 索引的分类 索引能够 ...

  6. 77.深入理解nodejs中Express的中间件

    转自:https://blog.csdn.net/huang100qi/article/details/80220012 Express是一个基于Node.js平台的web应用开发框架,在Node.j ...

  7. 错误日志写入到本地磁盘(lock 队列)

    今天照常在b站上看看编程:看到有讲错误日志处理的,自己没写过日志,就看看了看: 主要是在讲的时候牵扯到了队列和lock的知识点:这方面知识自己了解的更少,那就记录一下.

  8. Linux运维命令总结

    .什么是运维?什么是游戏运维? 1)运维是指大型组织已经建立好的网络软硬件的维护,就是要保证业务的上线与运作的正常, 在他运转的过程中,对他进行维护,他集合了网络.系统.数据库.开发.安全.监控于一身 ...

  9. newgrp---将当前登录用户临时加入到已有的组中

    Linux中的newgrp命令主要是将当前登录用户临时加入到已有的组中,用法如下: [linuxidc@localhost etc]$ newgrp grptest 上面命令的含义是将用户linuxi ...

  10. postgresql 不同数据库不同模式下的数据迁移

    编写不容易,转载请注明出处谢谢, 数据迁移 因为之前爬虫的时候,一部分数据并没有上传到服务器,在本地.本来用的就是postgresql,也没用多久,数据迁移的时候,也遇到了很多问题,第一次使pg_du ...