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

题意:

有一个计算机网络,n台计算机全部坏了,给你两种操作:

1.O x 修复第x台计算机

2.S x,y 判断两台计算机是否联通

联通的条件: 两台都修复好了,求距离小于d

思路:

数据很小,我们可以没修复一台就直接枚举已经修复的计算机找到距离小于d的,放到一个并查集里,查询的话直接查询是否再同一个并查集里就好了

实现代码:

//while(scanf("\n%c", &ope) != EOF)

#include<iostream>
#include<cstdio>
using namespace std;
const int M = 1e4+;
struct node{
int x,y,id;
}a[M],b[M];
int n,d;
int f[M];
int find(int x){
if(x == f[x]) return x;
return f[x] = find(f[x]);
} void mix(int x,int y){
int fx = find(x);
int fy = find(y);
if(fx != fy) f[fx] = fy;
} bool check(node a,node b){
double num = (a.x - b.x)*(a.x - b.x)+(a.y - b.y)*(a.y - b.y);
double num1 = d*d*1.0;
if(num <= num1) return ;
return ;
} int main()
{
char op;int k,l,r,cnt = ;
scanf("%d%d",&n,&d);
for(int i = ;i <= n;i ++)
scanf("%d%d",&a[i].x,&a[i].y),a[i].id = i;
for(int i = ;i <= n;i ++)
b[i].x = ,b[i].y=,b[i].id = ,f[i]= i;
while(scanf("\n%c", &op) != EOF){
if(op == 'O'){
scanf("%d",&k);
for(int i = ;i <= cnt;i ++)
if(check(b[i],a[k]))
mix(b[i].id,k); b[++cnt].x = a[k].x;b[cnt].y = a[k].y,b[cnt].id = a[k].id;
}
else{
scanf("%d%d",&l,&r);
if(find(l) == find(r)) printf("SUCCESS\n");
else printf("FAIL\n");
}
}
}

poj 2236 Wireless Network (并查集)的更多相关文章

  1. POJ 2236 Wireless Network (并查集)

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

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

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

  3. POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集

    POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...

  4. [并查集] POJ 2236 Wireless Network

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

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

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

  6. POJ 2236 Wireless Network(并查集)

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

  7. POJ 2236 Wireless Network (并查集)

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

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

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

  9. poj 2236 Wireless Network 【并查集】

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

随机推荐

  1. SessionState in ASP.NET Core(转载)

    问: In asp.net mvc we used to decorate controller for disabling session state by using attribute as [ ...

  2. Luogu3352 ZJOI2016 线段树 概率、区间DP

    传送门 考虑对于每一个位置\(i\),计算所有可能的结果出现的概率. 定义一个区间\([l,r]\)为对于\(x\)的极大区间,当且仅当\(\max \limits _{i=l}^r \{a_i\} ...

  3. CentOS安装noVNC,以Web方式交付VNC远程连接

    什么是noVNC noVNC 是一个 HTML5 VNC 客户端,采用 HTML 5 WebSockets, Canvas 和 JavaScript 实现,noVNC 被普遍用在各大云计算.虚拟机控制 ...

  4. YY:2018互联网创业公司应看清的事情

    潮流,技术,生活方式,盈利模式,消费人群几乎每年都在改变,2018,你看到的是怎样的一盘棋. 2018年是个很好的数字,很多互联网公司寄予希望在这个幸运数字年头奋起一搏,拿到一份可观的酬金.特别是一些 ...

  5. os模块 与 sys模块

    os模块 os模块是与操作系统交互的一个接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工 ...

  6. MongoDB日常运维操作命令小结

    总所周知,MongoDB是一个NoSQL非数据库系统,即一个数据库可以包含多个集合(Collection),每个集合对应于关系数据库中的表:而每个集合中可以存储一组由列标识的记录,列是可以自由定义的, ...

  7. Docker容器学习梳理 - 日常操作总结

    使用Docker已有一段时间了,今天正好有空梳理下自己平时操作Docker时的一些命令和注意细节: Docker 命令帮助 $ sudo docker Commands: attach Attach ...

  8. Safecracker-HDU1015

    题意 给你大写字母的字符串,A=1,...Z=26,以及target 问你是否有v - w^2 + x^3 - y^4 + z^5 = target 有输出字典序大的那个字符串 分析 dfs code ...

  9. qa_model

    [code=python] import os import sys import time import numpy import shelve import theano import thean ...

  10. 《linux内核设计与实现》第十八章

    第十八章 调试 调试工作艰难是内核级开发区别于用户级开发的一个显著特点. 一.准备开始 1.内和调试需要什么 一个bug(大部分bug通常都不是行为可靠而且定义明确的) 一个藏匿bug的内核版本(知道 ...