Wireless Network

Time Limit: 10000MS Memory Limit: 65536K

Total Submissions: 34265 Accepted: 14222

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


解题心得:

  1. 题意就是有n台电脑,每台电脑有一个坐标,它只可以联系和它距离在d内的电脑,现在每台电脑都是坏的,有两种操作,第一种就是维修某台电脑,第二种就是询问两台电脑是否可以通信。
  2. 时间给得很足啊,整整十秒,也就很简单了,每次暴力维护可以保持相互通信的电脑

#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1010; int father[maxn],n,d;
bool vis[maxn]; struct Pos {
int x,y;
}p[maxn]; void init() {
scanf("%d%d",&n,&d);
for(int i=1;i<=n;i++)
father[i] = i;
for(int i=1;i<=n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
} int find(int x) {
if(father[x] == x)
return x;
return father[x] = find(father[x]);
} void merge(int x,int y) {
int fx = find(x);
int fy = find(y);
father[fx] = fy;
} void fix(int pos) {
vis[pos] = true;
for(int i=1;i<=n;i++) {
if(vis[i]) {
int d2 = (p[i].x-p[pos].x)*(p[i].x-p[pos].x) + (p[i].y-p[pos].y)*(p[i].y-p[pos].y);
if(d2 <= d*d) {
if(find(i) != find(pos)) {
int fi = find(i);
for(int j=1;j<=n;j++) {
if(father[j] == fi)
merge(j,pos);
}
}
}
}
}
} int main(){
init();
char s[5];
while(scanf("%s",s) != EOF) {
int pos,a,b;
if(s[0] == 'O') {
scanf("%d",&pos);
if(vis[pos])
continue;
else
fix(pos);
} else {
scanf("%d%d",&a,&b);
if(vis[a] && vis[b] && find(a) == find(b))
printf("SUCCESS\n");
else
printf("FAIL\n");
}
}
return 0;
}

POJ:2236-Wireless Network的更多相关文章

  1. 【POJ】2236 Wireless Network

    题目链接:http://poj.org/problem?id=2236 题意:给你n台计算机的坐标.d是可通信的最大距离.有两个操作. 1.O p 表示修复计算机p. 2.S p q表示询问pq是否能 ...

  2. POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集

    POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...

  3. [并查集] POJ 2236 Wireless Network

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 25022   Accepted: 103 ...

  4. poj 2236:Wireless Network(并查集,提高题)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 677 ...

  5. POJ 2236 Wireless Network (并查集)

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

  6. poj 2236 Wireless Network 【并查集】

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16832   Accepted: 706 ...

  7. POJ 2236 Wireless Network [并查集+几何坐标 ]

    An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...

  8. POJ 2236 Wireless Network(并查集)

    传送门  Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 24513   Accepted ...

  9. POJ 2236 Wireless Network (并查集)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 18066   Accepted: 761 ...

  10. poj 2236 Wireless Network (并查集)

    链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...

随机推荐

  1. LOJ#137. 最小瓶颈路 加强版(Kruskal重构树 rmq求LCA)

    题意 三倍经验哇咔咔 #137. 最小瓶颈路 加强版 #6021. 「from CommonAnts」寻找 LCR #136. 最小瓶颈路 Sol 首先可以证明,两点之间边权最大值最小的路径一定是在最 ...

  2. Struts_ActionWildcard_通配符配置

    使用通配符,将配置量降到最低 不过,一定要遵守“约定由于配置”的原则 struts2.xml <?xml version="1.0" encoding="UTF-8 ...

  3. C盘空间太大,分区助手减小分区大小教程

    首先看一个需要缩小C盘或需要减少分区空间的一个例子:“我的电脑里C盘剩余空间为530GB,除了C盘外还有一个D盘,但D盘的空间不到30GB,另外还有两个隐藏分区,一个200MB,一个15GB.我想把C ...

  4. HDFS文件操作(命令行)

    HDFS是一种分布式文件系统,为MapReduce这种框架下的海量数据分布式处理而设计. Hadoop之HDFS文件操作常有两种方式,一种是命令行方式,即Hadoop提供了一套与Linux文件命令类似 ...

  5. ubuntu linux断点续传下载工具 uGet 的安装

    网址 http://ugetdm.com/downloads-ubuntu 使用命令行安装 sudo add-apt-repository ppa:plushuang-tw/uget-stable s ...

  6. IOS 制作常用代码的快捷方式

    输入可以变的对象或类型,要用<#name#>

  7. java 通过接口在后台管理器中生成数据

    需求:测试人员在后台批量添加数据很麻烦,特别是针对一款商品配置了英语,还需要手动添加法语.俄语.阿拉伯语,很麻烦,但是因为没有项目组配合,做个小工具批量生成数据就只有自己去研究了 第一步:通过抓包工具 ...

  8. Android(java)学习笔记97:使用GridView以及重写BaseAdapter

    1. BaseAdapter: 对于ListView.GridView.Gallery.Spinner等等,它是它们的适配器,直接继承自接口类Adapter的,使用BaseAdapter时需要重写很多 ...

  9. Codeforces Round #404 (Div. 2) ABC

    A. Anton and Polyhedrons Anton's favourite geometric figures are regular polyhedrons. Note that ther ...

  10. IIS无法识别的属性targetFramework

    出现这种错误是因为发布网站时iis的应用程序池默认使用的是.net framework v2.0.50727.4927,而开发的网站用的是.net framework 4.5,所以会出现这种错误. 我 ...