poj2236(并查集)
题意:一张图上分布着n台坏了的电脑,并知道它们的坐标。两台修好的电脑如果距离<=d就可以联网,也可以通过其他修好的电脑间接相连。给出操作“O x”表示修好x,给出操作“S x y”,请你判断x和y在此时有没有连接上。
分析:把每次修好的电脑能到达的都扔进一个集合里,然后直接判断即可。
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 100000000
#define inf 0x3f3f3f3f
#define eps 1e-9
#define N 1010
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PII pair<int,int>
using namespace std;
struct node
{
int x,y;
}p[N];
int fa[N],vis[N];
int dist(node a,node b)
{
return ((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int find(int x)
{
return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main()
{
int n;
int d;
while(scanf("%d%d",&n,&d)>)
{
for(int i=;i<=n;i++)fa[i]=i,vis[i]=;
for(int i=;i<=n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
}
char op[];
int x,y;
while(scanf("%s",op)>)
{
if(op[]=='O')
{
scanf("%d",&x);
vis[x]=;
for(int i=;i<=n;i++)
{
if(vis[i]&&dist(p[i],p[x])<=d*d)
{
int py=find(i);
int px=find(x);
fa[py]=px;
}
}
}
else
{
scanf("%d%d",&x,&y);
if(find(x)==find(y))puts("SUCCESS");
else puts("FAIL");
}
}
}
}
poj2236(并查集)的更多相关文章
- poj2236(并查集)
题目链接: http://poj.org/problem?id=2236 题意: 有n台计算机, 已知每台计算机的坐标, 初始时所有计算机都是坏的, 然后修复其中一些计算机, 已修复的计算机距离不超过 ...
- POJ2236(并查集入门)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 22977 Accepted: 961 ...
- 并查集 poj2236
网址:http://poj.org/problem?id=2236 题意:有n台坏的电脑,如果每两台电脑的距离不能超过d,那么这两台电脑有联系,用字符串O 表示标记第x台电脑维修了,用S判断从X到y是 ...
- poj-2236 Wireless Network &&poj-1611 The Suspects && poj-2524 Ubiquitous Religions (基础并查集)
http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由 ...
- poj2236 基础并查集
题目链接:http://poj.org/problem?id=2236 题目大意:城市网络由n台电脑组成,因地震全部瘫痪,现在进行修复,规定距离小于等于d的电脑修复之后是可以直接相连 进行若干操作,O ...
- 基础并查集poj2236
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- POJ2236 Wireless Network 并查集简单应用
Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...
- POJ-2236.WireleseNetwork.(并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 43199 Accepted: 178 ...
- 并查集——poj2236(带权并查集)
题目:Wireless Network 题意:给定n台已损坏计算机的位置和计算机最远通信距离d,然后分别根据命令执行以下两种操作: "O p" (1 <= p <= N ...
- poj2236 Wireless Network(并查集直接套模板
题目地址:http://poj.org/problem?id=2236 题目大意:n台电脑都坏了,只有距离小于d且被修好的电脑才可以互相联系,联系可传递.输入n和d,n个点的坐标x y.两个操作:O ...
随机推荐
- xml总结图--(来自传智播客视频资料)
- 使用iframe设置frameset的高度
index.html的页面代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "htt ...
- Managing your Actor Systems
今天偶然得机会,找到一篇不错得文章,现在分享给大家. 原文:http://www.kotancode.com/2013/02/15/managing-your-actor-systems/ If yo ...
- inode结构体成员详解
概述:inode译成中文就是索引节点,它用来存放档案及目录的基本信息,包含时间.档名.使用者及群组等.inode分为内存中的inode和文件系统中的inode,为了避免混淆,我们称前者为VFS ino ...
- G - Self Numbers(2.2.1)
G - Self Numbers(2.2.1) Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & % ...
- ASP.NET - 多文件上传,纯代码,不使用插件
解决方案: 前段代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Mu ...
- Tomcat详细用法学习(三)
本篇接上一篇<Tomcat详细用法学习(二)>,主要讲解服务器所要求的web应用的组织结构. 上一篇说到了如何使用服务器将自己的web应用映射成虚拟目录,以便于在浏览器中可以对自己开发的w ...
- c/c++ 动态申请数组
new和delete运算符用于动态分配和撤销内存的运算符 new使用方法: 1. 开辟单变量地址空间 1)new int; //开辟一个存放数组的存储空间,返回一个指向该存储空间的地址.in ...
- C++ - Operator Precedence
The following table lists the precedence and associativity of C++ operators. Operators are listed to ...
- javascript(七)document.write
<h1>test</h1> <button type="button" onclick="my_function">点击me ...