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. 对DOM操作的一些总结

    一.DOM节点 分为三大类: 1.元素节点 :<html>.<body>.<p>等标签 2.文本节点 :标签内的文本.例如<p>这就是文本节点</ ...

  2. <Android 基础(九)> Ndk配置与Demo

    介绍 The NDK is a toolset that allows you to implement parts of your app using native-code languages s ...

  3. react-native与原生界面相互跳转

    一.添加MyIntentModule类,并继承ReactContextBaseJavaModule实现其方法和构造函数.在该类中添加方法,注意:方法头要加@ReactMethod public cla ...

  4. WebAPI示例

    一.新建项目 二. 代码: Models.Products实体类 public class Product { /// <summary> /// 产品编号 /// </summar ...

  5. Azure 5 月新公布

    Azure 5 月新发布:CDN 高级版服务降价,MySQL Database 高级版本和新功能,以及应用程序网关中的 WAF 层发布   Azure CDN 高级版服务自 2017 年 5 月 1 ...

  6. ubuntu & sublime字体设置

    ubuntu # yahei http://pan.baidu.com/share/link?shareid=972621198&uk=1243888096&fid=333591974 ...

  7. T-SQL在线格式化工具

    http://www.dpriver.com/pp/sqlformat.htm?ref=g_wangz

  8. OpenGL学习 Following the Pipeline

    Passing Data to the Vertex Shader Vertex Attributes At the start of the OpenGL pipeline,we use the i ...

  9. 如何在windows下运行Linux命令?(转载)

    在windows上可以运行或使用linux下面的命令吗?可以,小编今天就来分享怎么样让Windows支持Linux命令,做这些安装和设置后,就可以非常方便的在windows系统中使用linux下面的命 ...

  10. dd-wrt ddns更新失败由于电信提供的ip不是公网ip

    由于电信提供的ip地址原来是公网的ip,后来电信通过nat提供一个内网ip,导致ddns更新失败.电话给电信客服10000号,让他们修改回来之后就可以了. 如果ddns更新失败,尤其是原本是正常的,后 ...