POJ - 2236 Wireless Network
Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 27292 | Accepted: 11291 |
Description
In the process of repairing the network, workers can take two kinds of operations at every moment, repairing a computer, or testing if two computers can communicate. Your job is to answer all the testing operations.
Input
1. "O p" (1 <= p <= N), which means repairing computer p.
2. "S p q" (1 <= p, q <= N), which means testing whether computer p and q can communicate.
The input will not exceed 300000 lines.
Output
Sample Input
4 1 0 1 0 2 0 3 0 4 O 1 O 2 O 4 S 1 4 O 3 S 1 4
Sample Output
FAIL SUCCESS代码:
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; const int N=1000+5; int par[N],rank[N]; void init(int n) {for(int i=0;i<=n;i++){par[i]=i;rank[i]=0;} } int find(int x) {if(par[x]==x)return x;else return par[x]=find(par[x]); } void unite(int x,int y) {x=find(x);y=find(y);if(x==y)return ;if(rank[x]<rank[y]){par[x]=y;}else{par[y]=x;if(rank[x]==rank[y])rank[x]++; } } int main() {int n,d;int x[N],y[N];cin>>n>>d;init(n);for(int i=1;i<=n;i++){scanf("%d%d",&x[i],&y[i]);}getchar();int vis[N]={0};int v[300000+5];int c=0;int a;char ch;while(cin>>ch){if(ch=='O'){cin>>a;vis[a]=1;v[c++]=a;for(int i=0;i<c-1;i++)if((x[a]-x[v[i]])*(x[a]-x[v[i]])+(y[a]-y[v[i]])*(y[a]-y[v[i]])<=d*d){unite(a,v[i]);}}else if(ch=='S'){int b;cin>>a>>b;if(find(a)==find(b)&&vis[a]&&vis[b])cout<<"SUCCESS"<<endl;else cout<<"FAIL"<<endl;}}return 0; }
转载于:https://www.cnblogs.com/widsom/p/6729833.html
POJ - 2236 Wireless Network相关推荐
- POJ 2236 Wireless Network 并查集
Wireless Network 并查集 Crawling in process... Crawling failed Time Limit:10000MS Memory Limit:6553 ...
- POJ 2236 Wireless Network (并查集)
Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...
- POJ 2236 Wireless Network
传送门:http://poj.org/problem?id=2236 解题思路: 利用了并查集 在操作一: 主要判断这个维修的电脑,和已经维修好的电脑的关系,如果他们的距离不大于题中限制的距离,就把他 ...
- POJ 2236 - Wireless Network ( 并查集 )
题意 一个计算机网络里的计算机都坏了, 现在有两种操作, "O p"代表修复了p机器, "S p q"代表检查 p, q 两台机器是否连接( 直线距离<= ...
- POJ 2236 Wireless Network
题意:有n台电脑,分布在一个二维坐标系中,两台距离不超过d的电脑可以相互通信,初始所有的电脑都是坏的,给出一组操作,第一种操作是修复某台电脑,只有修好的电脑才可以互相通信,第二种操作是询问两台电脑是否 ...
- A - Wireless Network POJ - 2236
A - Wireless Network POJ - 2236 并查集 if (op == 'S') {scanf("%d%d", &u, &v);if(vis[u ...
- 【POJ - 2236】Wireless Network (并查集)
题干: An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up ...
- [kuangbin带你飞]专题五 并查集 A - Wireless Network
A - Wireless Network 题目链接:https://vjudge.net/contest/66964#problem/A 题目: An earthquake takes place i ...
- Ad Hoc Networks TOPIC TWO <Wireless Network>【Personal Notes】
Ad Hoc Networks TOPIC TWO Wireless Network GSM: FDD+TDMA GSM network architecture 情景一:网络如何识别新用户 情景二: ...
- Ubuntu 18.04/20.04 安装Qualcomm Atheros QCA6174 802.11ac Wireless Network Adapter 驱动
Ubuntu 18.04/20.04下Qualcomm Atheros QCA6174驱动安装 缘起 原因分析 查找Google 详细步骤 缘起 买了新电脑,装上Ubuntu 20.04.奈何发现wi ...
最新文章
- android 调用百度sdk点位当前城市
- 链表问题14——在单链表种删除指定值的节点(方法二)
- 一次 HashSet 所引起的并发问题
- 我的Android进阶之旅------Android关于TextWatcher的初步了解
- python要学哪些_学python都要学哪些内容?
- 【Linux】一步一步学Linux——info命令(17)
- FJUT3703 这还是一道数论题(二分 + hash + manacher 或者 STL + hash 或者 后缀数组 + hash)题解...
- ANTLR入门:构建一种简单的表达语言
- ImageIO 框架详细解析
- WPF学习之路(十一)布局
- 数字倒序Java_怎么用Java编写一个程序,将输入的数字重新倒叙排列?
- 缓存MEMCACHE 使用原子性操作add,实现并发锁
- KMP算法经典题目--实现 strStr()
- drupal7 smtp+mimemail+mailsystem 实现发送html邮件
- DRL实战 : 强化学习在广告点击业务中的应用
- 长连接和短链接在服务器占用资源,TCP长连接和短链接及优缺点
- 魔兽争霸III 全图的制作
- 静听网+python爬虫+多线程+多进程+构建IP代理池
- 2022年美化UI二开某技术导航天下PHP源码
- 第二届国际计算成像会议-CITA
热门文章
- 关于iOS实现前台,后台,锁屏或关闭app语音播报
- linux读写进程内存函数,Linux内核模块里的读写函数
- jlink v9可升级固件‘_在rt-thread下实现OTA在线固件更新功能
- PHP实现文件上传,下载,批量下载
- gogs 创建新的仓库
- nginx access日志log_format优化之request_time 和upstream_response_time差别
- ECharts半圆环形图
- 本地 hosts 文件找不到怎么办
- 切换Pycharm的Python版本
- 行星级计算机,称霸两千余年的最快“计算机”——我国的算盘,两弹一星都靠它...