【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 ...
随机推荐
- Python浮点数(小数)运算误差的原因和解决办法
原因解释:浮点数(小数)在计算机中实际是以二进制存储的,并不精确.比如0.1是十进制,转换为二进制后就是一个无限循环的数:0.0001100110011001100110011001100110011 ...
- 牛逼哄哄的Qt库
目录 一.有价值 - 好的网站 - 好的文章 二.Qt开源库-工具 - QtXlsx--excel读写库 三.Qt开源库-控件 - libqxt编译 - Qwt - QCustomPlot - 其他 ...
- spark入门(三)键值对操作
1 简述 Spark为包含键值对类型的RDD提供了一些专有的操作.这些RDD被称为PairRDD. 2 创建PairRDD 2.1 在sprk中,很多存储键值对的数据在读取时直接返回由其键值对数据组成 ...
- redis 基础数据结构实现
参考文献 redis数据结构分析 Skip List(跳跃表)原理详解 redis 源码分析之内存布局 Redis 基础数据结构与对象 Redis设计与实现-第7章-压缩列表 在redis中构建了自己 ...
- struts2入门Demo
一.引入必要的jar包,所需jar包如下: 二.配置web.xml.主要目的是拦截请求 <?xml version="1.0" encoding="UTF-8&qu ...
- Protocol Buffer使用转换工具将proto文件转换成Java文件流程及使用
Client与Server的网络通信协议传输使用google protobuf,服务器端使用的是Java 一. Protocol Buffersprotobuf全称Google Protocol Bu ...
- pdfminer获取每页的layout
#! python2 # coding: utf-8 import sys from pdfminer import pdfparser from pdfminer import pdfdocumen ...
- 雅阁微信群、雅阁车友群、十代雅阁交流微信QQ群
最近一直在关注第十代雅阁,不论是普通汽油版本还是油电混动版本都很不错,在网上看到很多评测文章和视频 后续都会整理发布到微信群中. 由于论坛发帖,博客发文都不是很方便,为了及时沟通,先创建了微信群,方便 ...
- 个人永久性免费-Excel催化剂功能第70波-工作薄外部链接维护管理
Excel在数据领域万物互联的特性,其中一个使用场景是连接非本工作薄的外部性文件内容,如其他Excel工作薄文件里的内容或直接用OLE对象的方式嵌入一个文件链接,使其在不离开Excel环境,也可提供类 ...
- F#周报2019年第29期
新闻 ML.NET 1.2发布,包含Model Builder升级 NuGet.org上现在显示GitHub的使用情况 微基准测试设计准则 为线程添加mono.wasm支持 Haskell--经验总结 ...