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. 解决没有X11/Xlib.h 的错误

    1. 解决没有X11/Xlib.h 的错误Install XLib $sudo apt-get install libx11-dev 2. 提示错误:未找到软件源 解决办法很简单,更换另一个源就行了. ...

  2. 使用日志记录功能查看PHP扩展的执行过程

    了解过PHP内核的同学都知道,PHP的一次请求的生命周期 1.启动Apache后,PHP解释程序也随之启动.PHP调用各个扩展的MINIT方法,从而使这些扩展切换到可用状态 2.当一个页面请求发生时, ...

  3. android开发技巧

    1 Android去掉listView,gridView等系统自带阴影 当我们使用listView的时候,拉到顶,或是拉到底部的时候,我们会发现有系统自带的阴影效果出现,不同手机出现的颜色可能还会不一 ...

  4. 定义django admin的站点头,标题等

    admin.py from django.contrib import admin from app.models import Product # Register your models here ...

  5. DOM操作-克隆元素

    代码: ———————————————————————————— <script type="text/javascript">            //克隆元素   ...

  6. 二分图匹配之KM求二分图最佳匹配算法

    参考网址:http://blog.163.com/suntroop@yeah/blog/static/17012103120115185927194/ 对于具有二部划分( V1, V2 )的加权完全二 ...

  7. C语言strtok()函数:字符串分割

    头文件:#include <string.h> 定义函数:char * strtok(char *s, const char *delim); 函数说明:strtok()用来将字符串分割成 ...

  8. mvc 母版页、用户自定义控件

    母版页(Master) 1.母版页是与Controller无关的,母版页只是一个View文件,而没有任何Controller与之相对应. 2.其实在ASP.NET MVC中View的aspx与母版页并 ...

  9. Lotto

    Lotto Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submiss ...

  10. WisKey的眼神

    WisKey的眼神 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...