Wireless Network
Wireless Network
Time Limit: 10000MS Memory Limit: 65536K
Total Submissions: 19626 Accepted: 8234
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
Source
POJ Monthly,HQM
并查集的应用,将可以连接在一起纳入一个集合,进行查找
#include <iostream>
#include <cmath>
#include <map>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <string>
#include <queue>
#include <algorithm>
#define LL long long
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAX = 1100;
int pre[MAX];
struct node
{
int x;
int y;
}a[MAX];
int n,d;
bool vis[MAX];
int Find(int x)
{
return pre[x]==x?x:pre[x]=Find(pre[x]);
}
int Dis(node b,node c)//计算距离
{
return ((b.x-c.x)*(b.x-c.x)+(b.y-c.y)*(b.y-c.y));
}
int main()
{
char s[2];
scanf("%d %d",&n,&d);
for(int i=1;i<=n;i++)
{
pre[i]=i;
scanf("%d %d",&a[i].x,&a[i].y);
}
int site;
int u,v;
memset(vis,false,sizeof(vis));
while(~scanf("%s",s))
{
if(s[0]=='O')
{
scanf("%d",&site);
vis[site]=true;
int y = Find(site);
for(int i=1;i<=n;i++)
{
if(vis[i]&&i!=site)
{
int x = Find(i);
if(x!=y&&d*d>=Dis(a[site],a[i]))//这里判断错,应该让两个根节点连接
{
pre[x] = y;
}
}
}
}
else
{
scanf("%d %d",&u,&v);
if(Find(u)==Find(v))
{
printf("SUCCESS\n");
}
else
{
printf("FAIL\n");
}
}
}
return 0;
}
Wireless Network的更多相关文章
- [并查集] POJ 2236 Wireless Network
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 25022 Accepted: 103 ...
- POJ 2236 Wireless Network(并查集)
传送门 Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 24513 Accepted ...
- poj 2236:Wireless Network(并查集,提高题)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 16065 Accepted: 677 ...
- Top 10 Free Wireless Network hacking/monitoring tools for ethical hackers and businesses
There are lots of free tools available online to get easy access to the WiFi networks intended to he ...
- POJ 2236 Wireless Network (并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 18066 Accepted: 761 ...
- POJ 2236 Wireless Network (并查集)
Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...
- Wireless Network(POJ 2236)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 20724 Accepted: 871 ...
- POJ - 2336 Wireless Network
Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...
- POJ2236 Wireless Network 并查集简单应用
Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...
随机推荐
- Java基础之集合框架——使用HashMap地图(TryPhoneBook1)
控制台程序. 首先改进Peron类,使Person可以在地图中用作键,进而存储电话簿中的项.必须添加equals()方法并重写默认的hashCode()方法. import java.io.*; pu ...
- Linux内核源码分析方法
一.内核源码之我见 Linux内核代码的庞大令不少人“望而生畏”,也正因为如此,使得人们对Linux的了解仅处于泛泛的层次.如果想透析Linux,深入操作系统的本质,阅读内核源码是最有效的途径.我们都 ...
- PostgreSQL/bin
pg_receivexlog pg_receivexlog—以流的方式从一个PostgreSQL集簇得到事务日志 pg_receivexlog被用来从一个运行着的PostgreSQL集簇以流的方式得到 ...
- PHP——字符串处理部分
PHP——字符串处理 下面我们来讲一下我们经常使用的一些字符串处理的函数 1.string(变量);——取这个变量里面的字符串的长度 2.var_dump(变量a,变量b);——判断两个变量里面的字符 ...
- php 随机生成
php随机生成6位字符串: $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; $max = ...
- php中时间戳和日期格式的转换
一,PHP时间戳函数获取指定日期的unix时间戳 strtotime(”2009-1-22″) 示例如下: echo strtotime(”2009-1-22″) 结果:1232553600 说明:返 ...
- clock gate cell
clock gate的cell多采用latch的形式,来实现,尽可能避免glitch的产生. 可以的verilog建模方式: module cell_ckgate(TE,E,CP,Q) input ...
- 编译php时出现xsl错误的解决方法
是因为系统没安装一个叫 libxslt-devel 的包, 安装上就好了. 附编译php时的常见错误: http://www.myhack58.com/Article/sort099/sort0102 ...
- 经典SQL
一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...
- oracle中的函数
ORACLE中函数 Oracle已经内建了许多函数,不同的函数有不同的作用和用法,有的函数只能作用在一个记录行上,有的能够作用在多个记录行上,不同的函数可能处理不同的数据类型.常见的 ...