Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 50348   Accepted: 20619

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

Source

[Submit]   [Go Back]   [Status]   [Discuss]

题意

   有n个坏掉的卫星,每次操作‘O’可以修好一个,如果卫星之间都是‘修好的’状态且间距小于‘d',就可以通讯。

思路

   并查集的时候判断一下两卫星之间距离即可。

CODE

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream> #define dbg(x) cout << #x << "=" << x << endl using namespace std;
const int maxn = ; int fa[maxn], dis[maxn];
int n,m,ans,cnt;
int d;
int canuse[maxn]; struct node {
int x, y;
}a[maxn]; void init()
{
for(int i = ; i <= n; i++) {
fa[i] = i;
}
} double cal(node a, node b) {
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y) * (a.y - b.y));
} int fid(int x)
{
int r = x;
while(fa[r] != r) {
//if(cal(a[fa[r]],a[r]) <= d)
r = fa[r];
}
int i,j;///路径压缩
i = x;
while(fa[i] != r) {
//if(cal(a[fa[i]],a[r]) <= d) {
j = fa[i];
fa[i] = r;
i = j; }
return r;
} void join(int r1, int r2)///合并
{
int fidroot1 = fid(r1), fidroot2 = fid(r2);
if(fidroot1 != fidroot2) {
fa[fidroot2] = fidroot1;
}
} int main()
{
scanf("%d %d",&n, &d);
init();
for(int i = ; i <= n; ++i) {
scanf("%d %d",&a[i].x, &a[i].y);
}
getchar();
char ch[];
int p,q;
int cnt = ;
while(scanf("%s", ch) != EOF) {
//dbg(ch[0]);
if(ch[] == 'O') {
scanf("%d",&p);
//getchar();
canuse[cnt++] = p;
for(int i = ; i < cnt-; ++i) {
if(cal(a[canuse[i]],a[p]) <= double(d)) {
join(canuse[i],p);
}
}
}
if(ch[] == 'S') {
scanf("%d %d",&p,&q);
//getchar(); //join(p,q);
if(fid(p) == fid(q)) {
puts("SUCCESS");
}
else {
puts("FAIL");
}
}
}
return ;
}

A - Wireless Network POJ - 2236-kuangbin带你飞的更多相关文章

  1. Wireless Network(POJ 2236)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 20724   Accepted: 871 ...

  2. Day5 - B - Wireless Network POJ - 2236

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

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

    链接: http://poj.org/problem?id=2236 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...

  4. DisJSet:Wireless Network(POJ 2236)

      无线电网络 题目大意:就是地震后,所有的电脑都坏了,现在可以修复,而且要重新连成一个网络,两台电脑之间最大连接距离为D,两台电脑可以有中继电脑,按O修复电脑,按S测试两台电脑是否有链接,如果有就输 ...

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

    #include<iostream> #include<vector> #include<string> #include<cmath> #includ ...

  6. A - Wireless Network POJ - 2236

    题目大意:有n台坏掉的电脑,给出每台电脑的坐标,然后每次询问输入0(字符) x,表示电脑x恢复正常,输入S x y 询问x和y是否可以联网.只要是x和y的距离小于距离d,那么就可以联网,如果有个中介c ...

  7. 迷宫问题 POJ - 3984 [kuangbin带你飞]专题一 简单搜索

    定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, ...

  8. Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索

    Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...

  9. Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  10. 棋盘问题 POJ - 1321 [kuangbin带你飞]专题一 简单搜索

    在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C. ...

随机推荐

  1. 在Kali linux下使用docker配置sqli-labs(国内源的配置和系统软件更新)

    本篇blog导航: ~前言 ~第一步:在安装好的kali配置国内源 ~第二步:安装docker ~第三步:docker下安装sqli-labs ~写在最后. 前言: 最近闲来无事,在闯关sqli-la ...

  2. GNU make doc - 函数总结

    $(value variable) 使用variable未展开状态的值 FOO = $(PATH) all: $(warning $(FOO)) $(warning $(value FOO)) #ou ...

  3. ASP .NET CORE 源码地址

    ASP .NET CORE 源码地址:https://github.com/dotnet/ 下拉可以查找相应的源码信息, 例如:查找 ASP .NET CORE Microsoft.Extension ...

  4. python实现串口通讯小程序(GUI界面)

    python实现串口通讯小程序(GUI界面) 使用python实现串口通讯需要使用python的pyserial库来实现,这个库在安装python的时候没有自动进行安装,需要自己进行安装. 1.安装p ...

  5. springCloud进阶(微服务架构&Eureka)

    springCloud进阶(微服务架构&Eureka) 1. 微服务集群 1.1 为什么要集群 为了提供并发量,有时同一个服务提供者可以部署多个(商品服务).这个客户端在调用时要根据一定的负责 ...

  6. clr via c# Array2

    1,Array类型生成方式以及实际类型 private static void ArrayIntro() { String[] sa = new String[1]; Array a1 = Array ...

  7. C++中字符常量与字符常量不能直接相加

    定义string变量,并进行初始化,如下: string s1 = "Hello"; string s2 = s1 + "World"; string s3 = ...

  8. 数据库MySQL中关于“多表关联更新”的那些事

    在常见的sql中,我们经常在查询中进行多表关联查询,用的比较熟练.今天在开发中遇到一个实际业务场景是多表关联更新,一时不知所措.本着多学习的态度,没有直接写java代码去实现,终于把多表关联更新的sq ...

  9. 吴裕雄--天生自然HADOOP操作实验学习笔记:hbase的shell应用v2.0

    HRegion 当表的大小超过设置值的时候,HBase会自动地将表划分为不同的区域,每个区域包含所有行的一个子集.对用户来说,每个表是一堆数据的集合,靠主键来区分.从物理上来说,一张表被拆分成了多块, ...

  10. GHO文件安装到Vmware的两种姿势

    1.使用 Ghost11.5.1.2269 将gho转换为vmdk文件(虚拟机硬盘),Vmware新建虚拟机自定义配置,然后添加已有的虚拟硬盘文件. 注意ghost的版本,如果你是用Ghost11.5 ...