Wireless Network
题目链接:http://poj.org/problem?id=2236
Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 27292   Accepted: 11291

Description

An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are repaired one by one, and the network gradually began to work again. Because of the hardware restricts, each computer can only directly communicate with the computers that are not farther than d meters from it. But every computer can be regarded as the intermediary of the communication between two other computers, that is to say computer A and computer B can communicate if computer A and computer B can communicate directly or there is a computer C that can communicate with both A and B.

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

The first line contains two integers N and d (1 <= N <= 1001, 0 <= d <= 20000). Here N is the number of computers, which are numbered from 1 to N, and D is the maximum distance two computers can communicate directly. In the next N lines, each contains two integers xi, yi (0 <= xi, yi <= 10000), which is the coordinate of N computers. From the (N+1)-th line to the end of input, there are operations, which are carried out one by one. Each line contains an operation in one of following two formats: 
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

For each Testing operation, print "SUCCESS" if the two computers can communicate, or "FAIL" if not.

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相关推荐

  1. POJ 2236 Wireless Network 并查集

    Wireless Network 并查集 Crawling in process... Crawling failed Time Limit:10000MS     Memory Limit:6553 ...

  2. POJ 2236 Wireless Network (并查集)

    Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...

  3. POJ 2236 Wireless Network

    传送门:http://poj.org/problem?id=2236 解题思路: 利用了并查集 在操作一: 主要判断这个维修的电脑,和已经维修好的电脑的关系,如果他们的距离不大于题中限制的距离,就把他 ...

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

    题意 一个计算机网络里的计算机都坏了, 现在有两种操作, "O p"代表修复了p机器, "S p q"代表检查 p, q 两台机器是否连接( 直线距离<= ...

  5. POJ 2236 Wireless Network

    题意:有n台电脑,分布在一个二维坐标系中,两台距离不超过d的电脑可以相互通信,初始所有的电脑都是坏的,给出一组操作,第一种操作是修复某台电脑,只有修好的电脑才可以互相通信,第二种操作是询问两台电脑是否 ...

  6. A - Wireless Network POJ - 2236

    A - Wireless Network POJ - 2236 并查集 if (op == 'S') {scanf("%d%d", &u, &v);if(vis[u ...

  7. 【POJ - 2236】Wireless Network (并查集)

    题干: An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up ...

  8. [kuangbin带你飞]专题五 并查集 A - Wireless Network

    A - Wireless Network 题目链接:https://vjudge.net/contest/66964#problem/A 题目: An earthquake takes place i ...

  9. Ad Hoc Networks TOPIC TWO <Wireless Network>【Personal Notes】

    Ad Hoc Networks TOPIC TWO Wireless Network GSM: FDD+TDMA GSM network architecture 情景一:网络如何识别新用户 情景二: ...

  10. 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 ...

最新文章

  1. android 调用百度sdk点位当前城市
  2. 链表问题14——在单链表种删除指定值的节点(方法二)
  3. 一次 HashSet 所引起的并发问题
  4. 我的Android进阶之旅------Android关于TextWatcher的初步了解
  5. python要学哪些_学python都要学哪些内容?
  6. 【Linux】一步一步学Linux——info命令(17)
  7. FJUT3703 这还是一道数论题(二分 + hash + manacher 或者 STL + hash 或者 后缀数组 + hash)题解...
  8. ANTLR入门:构建一种简单的表达语言
  9. ImageIO 框架详细解析
  10. WPF学习之路(十一)布局
  11. 数字倒序Java_怎么用Java编写一个程序,将输入的数字重新倒叙排列?
  12. 缓存MEMCACHE 使用原子性操作add,实现并发锁
  13. KMP算法经典题目--实现 strStr()
  14. drupal7 smtp+mimemail+mailsystem 实现发送html邮件
  15. DRL实战 : 强化学习在广告点击业务中的应用
  16. 长连接和短链接在服务器占用资源,TCP长连接和短链接及优缺点
  17. 魔兽争霸III 全图的制作
  18. 静听网+python爬虫+多线程+多进程+构建IP代理池
  19. 2022年美化UI二开某技术导航天下PHP源码
  20. 第二届国际计算成像会议-CITA

热门文章

  1. 关于iOS实现前台,后台,锁屏或关闭app语音播报
  2. linux读写进程内存函数,Linux内核模块里的读写函数
  3. jlink v9可升级固件‘_在rt-thread下实现OTA在线固件更新功能
  4. PHP实现文件上传,下载,批量下载
  5. gogs 创建新的仓库
  6. nginx access日志log_format优化之request_time 和upstream_response_time差别
  7. ECharts半圆环形图
  8. 本地 hosts 文件找不到怎么办
  9. 切换Pycharm的Python版本
  10. 行星级计算机,称霸两千余年的最快“计算机”——我国的算盘,两弹一星都靠它...