【POJ - 2236】Wireless Network (并查集)
Wireless Network
这接翻译了
Descriptions
在修复网络的过程中,工作人员可以随时进行两种操作,修复计算机或测试两台计算机是否可以通信。你的工作是回答所有的测试操作。
Input
1。“O p”(1 <= p <= N),表示修复计算机p。
2.“S p q”(1 <= p,q <= N),这意味着测试计算机p和q是否可以通信。
输入不会超过300000行。
Output
Sample Output
4 1
0 1
0 2
0 3
0 4
1
O 2
O 4
S 1 4
O 3
S 1 4
Sample Output
FAIL
SUCCESS
题目链接
https://vjudge.net/problem/POJ-2236
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 100000+5
using namespace std;
int n,d;
int dx[Maxn];//坐标
int dy[Maxn];
int par[Maxn];//par[i] i的根
int pairs[Maxn];//pairs[i]=p 第i个修好的电脑编号为p
int findr(int x)//查询根
{
if(par[x]==x)
return x;
return par[x]=findr(par[x]);
}
void unite(int x,int y)//合并
{
x=findr(x);
y=findr(y);
if(x==y)//根相同不用管
return;
par[x]=y;//若根不同,y并入x,则y的根为x,同理x也能并入y 这里随意
}
double dis(int a,int b)//求距离
{
return sqrt( (double)((dx[a]-dx[b])*(dx[a]-dx[b]) + (dy[a]-dy[b])*(dy[a]-dy[b])) );
}
int main()
{
MEM(pairs,);
cin>>n>>d;
for(int i=; i<n; i++)
cin>>dx[i]>>dy[i];//集合初始化
for(int i=; i<n; i++)
par[i]=i;
int p,q,len=;
char op;
while(cin>>op)
{
if(op=='O')
{
cin>>p;
p--;
pairs[len++]=p;
for(int i=; i<len; i++)
{
if(dis(pairs[i],p)<=(double)d)//判断距离
unite(pairs[i],p);//合并集合
}
}
else
{
cin>>p>>q;
p--,q--;
if(findr(p)==findr(q))//查根
cout<<"SUCCESS"<<endl;
else
cout<<"FAIL"<<endl;
}
}
return ;
}
【POJ - 2236】Wireless Network (并查集)的更多相关文章
- POJ 2236 Wireless Network (并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 18066 Accepted: 761 ...
- poj 2236 Wireless Network (并查集)
链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...
- POJ 2236 Wireless Network [并查集+几何坐标 ]
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- 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 ...
- POJ 2236 Wireless Network(并查集)
传送门 Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 24513 Accepted ...
- POJ 2236 Wireless Network (并查集)
Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...
- [ An Ac a Day ^_^ ] [kuangbin带你飞]专题五 并查集 POJ 2236 Wireless Network
题意: 一次地震震坏了所有网点 现在开始修复它们 有N个点 距离为d的网点可以进行通信 O p 代表p点已经修复 S p q 代表询问p q之间是否能够通信 思路: 基础并查集 每次修复一个点重新 ...
- poj 2236 Wireless Network 【并查集】
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 16832 Accepted: 706 ...
随机推荐
- ajax 的简单请求,get的加法运算,post加法运算,用户登录认证
视图函数部分 from django.shortcuts import render, HttpResponse import time from app01.models import User i ...
- Python题整理
1.Python的多态.鸭子类型? 2.Python的序列化工具有哪些? 3.Python处理Excel的工具有哪些? 4.Python处理Graph的算法库有哪些? 5.Python的dict是基于 ...
- C++学习书籍推荐《Effective C++ 第三版(英文)》下载
百度云及其他网盘下载地址:点我 作者简介 Scott Meyers is one of the world's foremost authorities on C++, providing train ...
- c++学习书籍推荐《C++编程思想第二卷》下载
百度云及其他网盘下载地址:点我 编辑推荐 <C++编程思想>(第2卷)是惟一一本如此清晰地阐述如何重新思考以面向对象方法构造程序的书籍.<C++编程思想>(第2卷)介绍实用的编 ...
- Java学习笔记之---构造方法
Java学习笔记之---构造方法 (一)构造方法的特性 构造方法不能被对象单独调用 构造方法与类同名且没有返回值 构造方法只能在对象实例化的时候被调用 当没有指定构造方法时,系统会自动添加无参的构造方 ...
- 三个标签完成springboot定时任务配置
1. 问题描述 Java项目定时任务是必备模块,月高风黑夜跑个批处理,记录或者统计一些系统信息. 2. 解决方案: 结合springboot,只需三个标签就能完成定时任务配置. 2.1 标签1 用在s ...
- VNC服务配置
Windows通过VNC远程桌面访问Ubuntu设备:一个WIN7的机器,一个系统为Ubuntu的机器 (二者可以均可为虚拟机或实体机) 目的:在Windows系统上通过VNC远程访问Ubuntu. ...
- [Linxu] Ubuntu下载mysql
//下载: sudo apt install mysql-server sudo apt install mysql-client sudo apt install libmysqlclient-de ...
- Spring Boot从入门到实战(十):异步处理
原文地址:http://blog.jboost.cn/2019/07/22/springboot-async.html 在业务开发中,有时候会遇到一些非核心的附加功能,比如短信或微信模板消息通知,或者 ...
- golang "[]uint8" to string
关于Uinit8和Byte: The Go Programming Language Specification Numeric types uint8 the set of all unsigned ...