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. SharePoint2013 Excel导出好的代码

    C#Excel操作类ExcelHelper.cs 来源:http://www.hellocsharp.com/article/67.aspx C#源码世界 发布于: 2014-09-12 使用本类之前 ...

  2. vs打开项目,创建虚拟目录,提示权限不足无法写入配置文件

    如题,从源代码管理器上获取下来程序后,自己打开始,提示如题,尝试过以管理员启动vs,给目录权限提升,修改csproj项目配置文件(修改userIIS节点)and so on,无意间在用别的文档编辑器编 ...

  3. sipcal

    sudo apt-get install sipcalc sipcalc 10.120.148.xx/20

  4. Hibernate框架--对象的状态,缓存, 映射

    回顾Hibernate第二天: 1.  一对多与多对一 2. 多对多 3. inverse/cascade 4. 关联关系的维护 一对多: <set name="映射的集合属性&quo ...

  5. [转]html 移动互联网终端的javascript touch事件,touchstart, touchend, touchmove

    前言 如果我们允许用户在页面上用类似桌面浏览器鼠标手势的方式来控制WEB APP,这个页面上肯定是有很多可点击区域的,如果用户触摸到了那些可点击区域怎么办呢??诸如智能手机和平板电脑一类的移动设备通常 ...

  6. Elasticsearch Java虚拟机配置详解(转)

    引言: 今天,事情终于发生了.Java6(Mustang),是2006年早些时候出来的,至今仍然应用在众多生产环境中,现在终于走到了尽头.已经没有什么理由阻止迁移到Java7(Dolphin)上了. ...

  7. 拦截asp.net mvc输出流做处理, 拦截HTML文本(asp.net MVC版)

    以前的一个贴子写过一个webForm的拦截HTML输出流的版本,最近用到mvc时用同样的方式发生一些问题. 如下图 查了好久也不知道啥原因. 好吧, 我最后选择放弃. 想起以前自定义Response. ...

  8. msdn我告诉你

    http://msdn.itellyou.cn/ 微软旗下所有的msdn订阅软件资源 均为ed2k资源 Business Solutions MSDN Library 工具和资源 应用程序 开发人员工 ...

  9. LoadRunner学习知多少--IP欺骗使用

    使用IP欺骗功能时,需要将系统防火墙,杀毒软件关闭(如果有影响的话) 一.为什么要设置IP欺骗 1. 当某个IP的访问过于频繁,或者访问量过大时,服务器会拒绝访问请求,这时候通过IP欺骗可以增加访问频 ...

  10. Ajax应用-定义一套自己的Ajax框架

    —————————————————————————— <script type="text/javascript">            //定义个一个functio ...