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

O
O
O
S
O
S
Sample Output FAIL
SUCCESS

题目链接:http://poj.org/problem?id=2236

******************************************

题意:给你n台电脑,然后给出给各电脑坐标,距离不超过d才可以沟通。一开始电脑都是坏的,o操作代表修电脑,s操作判断x与y是否可以联通。

分析:s查询的时候就是简单的并查集,但对于修复更新的时候要注意距离的判断,符合要求的才可以。

一开始FAIL 写成了FALL,唉

 #include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<algorithm>
#include<time.h>
using namespace std; #define N 1550
#define INF 0x3f3f3f3f int Father[N]; struct node
{
int x,y,v;
}a[N];///保存所有的村庄,v标记是否已经修复 int Find(int x)
{
if(x != Father[x])
x=Find(Father[x]);
return x;
} int Len(node a,node b)///求两个村庄的距离
{
int x=b.x-a.x;
int y=b.y-a.y;
return x*x+y*y;
} int main()
{
int n,i,b,c,d;
char s[]; scanf("%d %d", &n,&d);
d=d*d;///因为距离只做判断不做计算,所以直接用平方数判断可以避免小数,更加精确 for(i=;i<=n;i++)
{
scanf("%d %d", &a[i].x,&a[i].y);
a[i].v=;
Father[i]=i;
} while(scanf("%s", s) != EOF)
{
if(s[]=='O')
{
scanf("%d", &b);
if(a[b].v==)
{
a[b].v=;
for(i=;i<=n;i++)
{
if(b!=i&&a[i].v&&Len(a[i],a[b])<=d)
{
int j=Find(i);
int k=Find(b); Father[k]=j;
}
}
} }
else
{
scanf("%d %d", &b,&c);
int j=Find(b);
int k=Find(c);
if(j==k)
printf("SUCCESS\n");
else
printf("FAIL\n");
}
}
return ;
}

POJ - 2336 Wireless Network的更多相关文章

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

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

  2. [并查集] POJ 2236 Wireless Network

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

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

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

  4. POJ 2236 Wireless Network(并查集)

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

  5. POJ 2236 Wireless Network (并查集)

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

  6. POJ 2236 Wireless Network (并查集)

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

  7. poj 2236 Wireless Network 【并查集】

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

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

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

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

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

随机推荐

  1. OC类的本质及分类

    (一)类的本质 类对象(class object)与实例对象(instance object) 类本身也是一个对象,是class类型的对象,简称“类对象”. 在/usr/include/objc/ob ...

  2. spring源码

    今天看了看spring对于视图解析的源码,发现还不是那些思想,internalResourceView里的一个渲染方法 protected void exposeModelAsRequestAttri ...

  3. Openjudge-计算概论(A)-大象喝水

    描述 一只大象口渴了,要喝20升水才能解渴,但现在只有一个深h厘米,底面半径为r厘米的小圆桶(h和r都是整数).问大象至少要喝多少桶水才会解渴. 输入输入有一行:包行两个整数,以一个空格分开,分别表示 ...

  4. 对AppStore中的项目进行评分(转载)

    在ios6.0前跳转到appstore评分一般是直接跳转到appstore评分NSString *evaluateString = [NSString stringWithFormat:@" ...

  5. redis数据类型:lists

    redis的list类型其实就是一个每个子元素都是string类型的双向链表. 我们可以通过push,pop操作从链表的头部或者尾部添加删除元素,这样list即可以作为 栈,又可以作为队列. lpus ...

  6. JS跨域解决方式 window.name

    window.name 传输技术,原本是 Thomas Frank 用于解决 cookie 的一些劣势(每个域名 4 x 20 Kb 的限制.数据只能是字符串.设置和获取 cookie 语法的复杂等等 ...

  7. 实验六 多线程编程 1.随便选择两个城市作为预选旅游目标。实现两个独立的线程分别显示10次城市名,每次显示后休眠一段随机时间(1000ms以内),哪个先显示完毕,就决定去哪个城市。分别用Runnable接口和Thread类实现。

    //继承Thread类 package zuoye; //继承Thread类 public class City extends Thread{ private String name; public ...

  8. vs中的各种快捷键

    1. VS注释与取消注释快捷键 CTRL + K , CTRL + C(注释) CTRL + K , CTRL + U(取消注释)

  9. postgresql 修改属性

    up vote2down votefavorite From this article, I tried to update or delete property of a JSONB column: ...

  10. HDU 5795 A Simple Nim

    打表找SG函数规律. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> ...