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 题目链接:http://poj.org/problem?id=2236

题目要求就是:给你n个坏的计算机 和 限制的连通距离d,然后输入这几台计算机的坐标。
然后输入一个字符O或S,O表示后面输入的 p 这台计算机修好了,S是要你求p和q这两台计算机是否能连通,连通输出SUCCESS否则输出FAIL
现在说明两台计算机能连通的条件:一、这两台计算机的距离要<=d,二、这两台计算机要求都已经修好了 我因为把FAIL写成FALL,wa的我都想哭了,好伤心
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<iostream>
#include<algorithm>
#define N 1100
using namespace std;
struct node
{
int x,y;
};
node a[N];
int d,fa[N],vis[N]; int judge(int x,int y)
{
int d0=(a[x].x-a[y].x)*(a[x].x-a[y].x)+(a[x].y-a[y].y)*(a[x].y-a[y].y);
if(d0<=d*d)
return ;
return ;
} int Find(int x)
{
if(x!=fa[x])
fa[x]=Find(fa[x]);
return fa[x];
}
int main()
{
int n,i,k,x,y;
char str[N];
scanf("%d%d",&n,&d);
for(i=;i<=n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
for(i=;i<=n;i++)
fa[i]=i;
k=;
while(scanf("%s",str)!=EOF)
{
if(strcmp("O",str)==)
{
scanf("%d",&x);
for(i=;i<k;i++)
{
if(judge(x,vis[i])==)//判断两点间的距离是否<=d;
{
int dx=Find(x);
int dy=Find(vis[i]);
if(dx!=dy)
fa[dy]=dx;
}
}
vis[k]=x;
k++;
}
else
{
scanf("%d%d",&x,&y);
if(Find(x)==Find(y))
printf("SUCCESS\n");
else
printf("FAIL\n");
}
}
return ;
}
复习时又写了一遍感觉还可以:
View Co

Wireless Network--poj2236(并查集)的更多相关文章

  1. POJ2236:Wireless Network(并查集)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 39772   Accepted: 164 ...

  2. poj2236 Wireless Network(并查集直接套模板

    题目地址:http://poj.org/problem?id=2236 题目大意:n台电脑都坏了,只有距离小于d且被修好的电脑才可以互相联系,联系可传递.输入n和d,n个点的坐标x y.两个操作:O ...

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

    Wireless Network 这接翻译了 Descriptions 地震发生在东南亚.ACM(亚洲合作医疗团队)已经与膝上电脑建立了无线网络,但是一次意外的余震袭击,网络中的所有计算机都被打破了. ...

  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: 16065   Accepted: 677 ...

  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: 36363   Accepted: 150 ...

  8. poj 2236 Wireless Network 【并查集】

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

  9. Wireless Network(并查集)

    POJ - 2236 #include<iostream> #include<algorithm> #include<cstring> #include<cm ...

  10. POJ3694:Network(并查集+缩点+lca)

    Network Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 13172   Accepted: 4774 题目链接:htt ...

随机推荐

  1. iOS开发--提交应用Your binary is not optimized for iPhone 5

    ERROR ITMS-: "Your binary is not optimized for iPhone 5 - New iPhone apps and app updates submi ...

  2. C++ template —— tuple(十三)

    本系列博文中我们使用同类容器(如数组类型)来阐述模板的强大威力,同时,C/C++还具有包含异类对象的能力.这里的异类指的是类型不同,或者结构不同.tuple就是这样的一个类模板,它能够用于聚集不同类型 ...

  3. codeforces水题100道 第二十五题 Codeforces Round #197 A. Helpful Maths (Div. 2) (strings)

    题目链接:http://www.codeforces.com/problemset/problem/339/A题意:重新组合加法字符串,使得按照1,2,3的顺序进行排列.C++代码: #include ...

  4. RunLoop 总结及应用

      什么是RunLoop 注释:和ppt上总结的一样 和代码一块去理解 从字面上看 运行循环 跑圈 循环 基本作用 保持程序的持续运行(比如主运行循环) 处理App中的各种事件(比如触摸事件.定时器事 ...

  5. window下线程同步之(Mutex(互斥器) )

    使用方法: 1.创建一个互斥器:CreateMutex: 2.打开一个已经存在的互斥器:OpenMutex: 3.获得互斥器的拥有权:WaitForSingleObject.WaitForMultip ...

  6. ATM技术基本原理

    1 术语.定义和缩略语 1.1 术语.定义 术语/定义 说    明 ATM层 位于B-ISDN/ATM网络协议参考模型的第二层,完成交换.路由选择和信元复用功能.ATM层的基本处理单位是信元. AA ...

  7. 【Spring系列】Spring AOP面向切面编程

    前言 接上一篇文章,在上午中使用了切面做防重复控制,本文着重介绍切面AOP. 在开发中,有一些功能行为是通用的,比如.日志管理.安全和事务,它们有一个共同点就是分布于应用中的多处,这种功能被称为横切关 ...

  8. jade(pug)学习笔记(待填充.......)

    深刻认识到总结知识点的重要性,不然遇到似曾相识的问题,要翻老半天的百度才能解决.20171018 pug——文字内部嵌入结构 比如: <a class = "href"> ...

  9. Android.mk(5) 计算怎么办?

    https://www.jianshu.com/p/57c01e97c9b8 计算怎么办? 前面我们把Makefile做为一门语言的主要特性大致做了一个描述,它集合了目标式的模式和函数式的模式,还有大 ...

  10. php sqlserver及xdebug扩展配置

    ;extension=php_bz2.dllextension=php_curl.dll;extension=php_fileinfo.dll;extension=php_ftp.dll;extens ...