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. Ansible 使用 Playbook 安装 Nginx

    思路:先在一台机器上编译安装好 Nginx,打包,然后通过 Ansible 下发 [root@localhost ~]$ cd /etc/ansible/ [root@localhost ansibl ...

  2. this关键字制定对象的属性

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. [原]如何为SqlServer2008数据库分配用户

    前言: 当一个项目完成后,为了数据安全,总会对该项目的数据库分配一个用户,应该说总会创建一个用户来管理这个数据库,并且这个用户只能管理这个数据库.搞了好多次,每次都忘记怎么设置,所以写一篇博文记录一下 ...

  4. 使用java连接数据库以后显示“ Establishing SSL connection without server's identity verification is not recommended”的警告如何解决

    今天写了一段查询数据库的操作,如下 package MySQL; import java.sql.*; public class MySQL { //JDBC驱动名以及数据库URL static fi ...

  5. Python进阶 学习笔记(一)

    (笔记范围:第一章 课程介绍:第二章 函数式编程:第三章 模块) Python支持的函数式编程 不是纯函数式编程:允许有变量 支持高阶函数:函数也可以作为变量传入 支持闭包:有了闭包就能返回函数 有限 ...

  6. luanet分布式lua框架

    luanet最初只是一个网络框架,它简单的封装了一些网络相关接口然后暴露到lua中,让lua可以构建简单的网络应用. 随着我的手游服务器的开发,我发现在C语言中要实现一个简洁易用的RPC调用接口并不容 ...

  7. UI设计中的高保真和低保真

    低保真一般用Axure Rp产出,高保真分两种,带交互的或不带交互的.不带交互的高保真直接根据低保真用PS产出即可.带交互的,需要 PS产出后,再切图,再使用Axure RP与低保真结合产出高保真. ...

  8. Linux 安装GCC讲解(在线和无网离线)

    本文主要介绍如何在无网络的环境下怎么离线安装GCC,如果有网,只需要通过命令 yum install gcc 进行安装就可以了,yum会自动把所有关联的依赖包也一起安装了,一键安装. yum inst ...

  9. Unity3D protobuf-net使用方式

    1.下载protobuf-net 2.创建Unity工程,创建一个Plugins文件夹,将protobuf-net解压把里面得protobuf-net放到Plugins 3.创建一个名为mcs的文本文 ...

  10. mvn deploy命令上传包

    需求:有的时候需要单独上传release jar包,因为存在工程代码在A内网SVN,Nexus在B内网.这种情况下使用VPN也无法解决Jar包发布的问题. 这个时候采取的方式只能是: 打出jar包 - ...