A - Wireless Network POJ - 2236
题目大意:有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的更多相关文章
- Wireless Network(POJ 2236)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 20724 Accepted: 871 ...
- Day5 - B - Wireless Network POJ - 2236
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- (并查集) Wireless Network --POJ --2236
链接: http://poj.org/problem?id=2236 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- DisJSet:Wireless Network(POJ 2236)
无线电网络 题目大意:就是地震后,所有的电脑都坏了,现在可以修复,而且要重新连成一个网络,两台电脑之间最大连接距离为D,两台电脑可以有中继电脑,按O修复电脑,按S测试两台电脑是否有链接,如果有就输 ...
- Wireless Network POJ - 2236 (并查集)
#include<iostream> #include<vector> #include<string> #include<cmath> #includ ...
- A - Wireless Network POJ - 2236-kuangbin带你飞
A - Wireless Network POJ - 2236 Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 50348 ...
- POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集
POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...
- [并查集] POJ 2236 Wireless Network
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 25022 Accepted: 103 ...
- poj 2236:Wireless Network(并查集,提高题)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 16065 Accepted: 677 ...
随机推荐
- python使用pip安装模块出现ReadTimeoutError: HTTPSConnectionPool的解决方法
今天使用pip安装第三库时,有时会报错: pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='file ...
- hdu3336 Counting the string kmp的next数组的应用
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/3336/ 题意就是要求一个字符串的所有前缀在字符串中出现的次数之和,我们容易想到kmp中的next数组,next[ ...
- 最简易 Pair of Topics解决方法
这个题花费了我两天的时间来解决,最终找到了两个比较简单的方法 首先这个题不难看出是寻找a[i]+a[j]<0的情况,我第一开始直接用两个for循环遍历通过不了,应该是复杂度太大了 第一个方法 # ...
- 微信小程序分享转发用法大全——自定义分享、全局分享、组合分享
官方提供的自定义分享 使用隐式页面配置函数实现的全局分享-推荐 使用隐式路由实现的全局分享-不推荐,仅供了解隐式路由 前言: 目前微信小程序只开放了页面自定义分享的API,为了能够更灵活的进行分享配置 ...
- 基于树莓派与YOLOv3模型的人体目标检测小车(一)
项目介绍: 本科毕业选的深度学习的毕设,一开始只是学习了一下YOLOv3模型, 按照作者的指示在官网上下载下来权重,配好环境跑出来Demo,后来想着只是跑模型会不会太单薄,于是想了能不能做出来个比较实 ...
- Building Applications with Force.com and VisualForce(Dev401)(十):Designing Applications for Multiple Users: Building Business Processes that You Want
Dev401-011: Building Business Processes that You Want Course Objectives1.Describe the capabilities o ...
- vim-1-window,buffer and tab
Summary:A buffer is the in-memory text of a file. A window is a viewport on a buffer. A tab page is ...
- class-dump的安装和使用
安装步骤 1.下载地址:http://stevenygard.com/projects/class-dump/ 2.打开终端输入 open /usr/local/bin 3.把dmg文件中的class ...
- vue-cli 引入axios及跨域使用
使用 cnpm 安装 axios cnpm install axios --save-dev 安装其他插件的时候,可以直接在 main.js 中引入并 Vue.use(),但是 axios 并不能 u ...
- [bzoj1800]fly 飞行棋<暴力>
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1800 说实话我这几天运气不错,随便在bzoj上找题都可以找到水题,这题在代码上没有丝毫难度 ...