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

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 <string>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <ctime>
using namespace std; const int SIZE = ;
int FATHER[SIZE],RANK[SIZE];
int N,D;
pair<int,int> G[SIZE];
vector<int> OK;
double DIS[SIZE][SIZE]; void ini(int);
int find_father(int);
void unite(int,int);
bool same(int,int);
double dis(pair<int,int>,pair<int,int>);
int main(void)
{
int x,y;
char ch; while(scanf("%d%d",&N,&D) != EOF)
{
ini(N);
for(int i = ;i <= N;i ++)
scanf("%d%d",&G[i].first,&G[i].second);
for(int i = ;i <= N;i ++)
for(int j = ;j <= N;j ++)
DIS[i][j] = dis(G[i],G[j]); while(scanf(" %c",&ch) != EOF)
if(ch == 'O')
{
scanf("%d",&x);
for(int i = ;i < OK.size();i ++)
if(DIS[x][OK[i]] <= D)
unite(x,OK[i]);
OK.push_back(x);
}
else
{
scanf("%d%d",&x,&y);
printf("%s\n",same(x,y) ? "SUCCESS" : "FAIL");
}
} return ;
} void ini(int n)
{
for(int i = ;i <= n;i ++)
{
FATHER[i] = i;
RANK[i] = ;
}
} int find_father(int n)
{
if(FATHER[n] == n)
return n;
return FATHER[n] = find_father(FATHER[n]);
} void unite(int x,int y)
{
x = find_father(x);
y = find_father(y); if(x == y)
return ;
if(RANK[x] < RANK[y])
FATHER[x] = y;
else
{
FATHER[y] = x;
if(RANK[x] == RANK[y])
RANK[y] ++;
}
} bool same(int x,int y)
{
return find_father(x) == find_father(y);
} double dis(pair<int,int> a,pair<int,int> b)
{
return sqrt(pow(a.first - b.first,) + pow(a.second - b.second,));
}

POJ 2236 Wireless Network (并查集)的更多相关文章

  1. poj 2236 Wireless Network (并查集)

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

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

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

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

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

  4. [并查集] POJ 2236 Wireless Network

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

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

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

  6. POJ 2236 Wireless Network(并查集)

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

  7. POJ 2236 Wireless Network (并查集)

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

  8. [ An Ac a Day ^_^ ] [kuangbin带你飞]专题五 并查集 POJ 2236 Wireless Network

    题意: 一次地震震坏了所有网点 现在开始修复它们 有N个点 距离为d的网点可以进行通信 O p   代表p点已经修复 S p q 代表询问p q之间是否能够通信 思路: 基础并查集 每次修复一个点重新 ...

  9. poj 2236 Wireless Network 【并查集】

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

随机推荐

  1. mvc4帮助类

    @App @AppState @Ajax @Cache @Context @Culture @Html @IsPost @Layout @Model @Output @OutputStack @Pag ...

  2. C:常量、变量 、 表达式 、运算符、 枚举

    常量 变量 表达式 运算符 枚举 1.布尔类型只有真和假 2运算符 >,<,<=,>=,==,!=.判断两个数是否相等要使用双等号‘==’.逻辑运算符的表达式结果非真即假,&a ...

  3. Oracle-11g-R2 RAC 环境下 GPnP Profile 文件

    GPnP Profile 文件的作用: GPnP Profile 文件是一个保存于 $GRID_HOME/gpnp/<hostname>/profiles/peer 目录下的小型 XML ...

  4. 解决NDK开发中Eclipse报错“Unresolved inclusion jni.h”的最终方法

    http://blog.csdn.net/zhubin215130/article/details/39347873

  5. 用ICSharpCode.SharpZipLib进行压缩

    今天过中秋节,当地时间(2013-09-08),公司也放假了,正好也闲着没事,就在网上学习学习,找找资料什么的.最近项目上可能会用到压缩的功能,所以自己就先在网上学习了,发现一个不错的用于压缩的DLL ...

  6. C++ Bit Fields

    http://msdn.microsoft.com/en-us/library/ewwyfdbe%28v=vs.71%29.aspx Note An unnamed bit field of widt ...

  7. addClass 函数

    javascript: function addClass(id,new_class){ var i,n=0; new_class=new_class.split(","); fo ...

  8. MPIO配置

    设置好两块网卡的IP(实用同一段IP,或者不同网段IP均可以配置多路径)iSCSI发起程序配置:1.添加发现(默认设置即可)2.目标-连接-高级:分别配置 本地适配器.发起程序IP.目标门户IP(此处 ...

  9. ubuntu12.04_64bit adb shell

    1.#adb shell 提示error: insufficient permissions for device 解决办法: 1)sudo gedit /etc/udev/rules.d/51-an ...

  10. [ACM] hdu 1181 变形课

    变形课 Problem Description 呃......变形课上Harry碰到了一点小麻烦,由于他并不像Hermione那样可以记住全部的咒语而任意的将一个棒球变成刺猬什么的,可是他发现了变形咒 ...