题目大意:有n台坏掉的电脑,给出每台电脑的坐标,然后每次询问输入0(字符) x,表示电脑x恢复正常,输入S x y 询问x和y是否可以联网。只要是x和y的距离小于距离d,那么就可以联网,如果有个中介c使得x到c的距离小于d,y到c的距离小于d,那么x和y也可以联网。

题解:当修复好一台电脑后,然后判断与之前修好的电脑的距离,小于d的话,用并查集连在一起。(没敢这样想,感觉这样会T....)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=2E4+;
int n,d;
int arrx[N],arry[N],pre[N];
int cnt[N];
int pos=;
int dis(int a,int b){
return pow(arrx[a]-arrx[b],)+pow(arry[a]-arry[b],)<=d*d;
}
int find(int x){
return x==pre[x]? x:pre[x]=find(pre[x]);
}
void unite(int x,int y){
x=find(x);y=find(y);
pre[x]=y;
}
bool check(int x,int y){
return find(x)==find(y);
}
int main(){
cin>>n>>d;
for(int i=;i<=n;i++) cin>>arrx[i]>>arry[i];
char s;
for(int i=;i<=n;i++) pre[i]=i;
while(cin>>s){
if(s=='S'){
int x,y;
scanf("%d%d",&x,&y);
if(check(x,y)) cout<<"SUCCESS"<<endl;
else cout<<"FAIL"<<endl;
}
else {
int x;cin>>x;
cnt[++pos]=x;
for(int i=;i<pos;i++){
if(dis(x,cnt[i])){
unite(x,cnt[i]);
}
}
}
}
return ;
}

A - Wireless Network POJ - 2236的更多相关文章

  1. Wireless Network(POJ 2236)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 20724   Accepted: 871 ...

  2. Day5 - B - Wireless Network POJ - 2236

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

  3. (并查集) Wireless Network --POJ --2236

    链接: http://poj.org/problem?id=2236 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...

  4. DisJSet:Wireless Network(POJ 2236)

      无线电网络 题目大意:就是地震后,所有的电脑都坏了,现在可以修复,而且要重新连成一个网络,两台电脑之间最大连接距离为D,两台电脑可以有中继电脑,按O修复电脑,按S测试两台电脑是否有链接,如果有就输 ...

  5. Wireless Network POJ - 2236 (并查集)

    #include<iostream> #include<vector> #include<string> #include<cmath> #includ ...

  6. A - Wireless Network POJ - 2236-kuangbin带你飞

    A - Wireless Network POJ - 2236 Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 50348 ...

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

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

  8. [并查集] POJ 2236 Wireless Network

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

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

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

随机推荐

  1. select_related prefetch_related

    # select_related与prefetch_related# # select_related帮你直接连表操作 查询数据 括号内只能放外键字段# # res = models.Book.obj ...

  2. vue one one

    目录 Vue 渐进式 JavaScript 框架 一.走进Vue 1.what -- 什么是Vue 2.why -- 为什么要学习Vue 3.special -- 特点 4.how -- 如何使用Vu ...

  3. PhpStorm+XAMPP+Xdebug 集成开发和断点调试环境配置

    0x01 Xdebug安装 参考:https://xdebug.org/docs/install cd xdebug-/ phpize sudo ./configure --enable-xdebug ...

  4. js正则校验表单

    /** * 表单校验规则 * 不符合规则时,返回错误文案 * 符合规则时,返回false */ var rules = {} // 是否必填 rules.required = function (va ...

  5. ysoserial分析【二】7u21和URLDNS

    目录 7u21 gadget链分析 hashCode绕过 参考 URLDNS 7u21 7u21中利用了TemplatesImpl来执行命令,结合动态代理.AnnotationInvocationHa ...

  6. 详解十大经典机器学习算法——EM算法

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是机器学习专题的第14篇文章,我们来聊聊大名鼎鼎的EM算法. EM算法的英文全称是Expectation-maximization al ...

  7. 【笔记3-26】Python语言基础

    编译型语言和解释型语言 编译型语言 C 先编译 解释型语言 Python 边执行边编译 Python的介绍 吉多·范罗苏姆 1991 解释型语言 Life is short you need Pyth ...

  8. 一份精简的Numpy使用指引(附python演练)

    欢迎大家关注我们的网站和系列教程:http://www.tensorflownews.com/,学习更多的机器学习.深度学习的知识! Numpy 的主要用途是以数组的形式进行数据操作. 机器学习中大多 ...

  9. [bzoj]1053反质数<暴搜>

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1053 感想:这道题拿到以后还是想去知道一个数的约数个数要怎么求,去网上搜了公式,但是还是没有思 ...

  10. Vue 里面对树状数组进行增删改查 的方法

    [{"id":"5e4c3b02fc984961a17607c37712eae0", "optLock":0, "parentId ...