来源poj2236

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

额,一开始题目没看清,其实就是简单的并查集,用一个vector存一下哪些编号被修好了,然后查一下哪些是可以和这个计算机相连的,然后连起来就好了

代码因为一开始没搞清 写的不好

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=10005;
struct PC
{
int x,y,f,temp;
}pc[N];
vector<int>v;
int l;
int find(int x)
{
if(pc[x].f==x)
return x;
return pc[x].f=find(pc[x].f);
}
double dist(int a,int b)
{
return sqrt(1.0*(pc[a].x-pc[b].x)*(pc[a].x-pc[b].x)+(pc[a].y-pc[b].y)*(pc[a].y-pc[b].y));
}
void Union(int x)
{
pc[x].temp=1;
rep(i,0,v.size())
{
if(v[i]!=x)
if(dist(v[i],x)<=l+eps)
{
pc[find(v[i])].f=x;
} }
v.push_back(x);
}
bool judge(int a,int b)
{
if(pc[a].temp==0||pc[b].temp==0) return false;
if(dist(a,b)<=l+eps) return true;
int fa=find(a),fb=find(b);
if(fa==fb) return true;
return false;
}
int main()
{
int n,x,y;
char c;
v.clear();
cin>>n>>l;
rep(i,1,n+1)
{
sf("%d%d",&pc[i].x,&pc[i].y);
pc[i].f=i;pc[i].temp=0;
}
getchar();
while(sf("%c",&c)!=EOF)
{
if(c=='O')
{
sf("%d",&x);
Union(x);
}else
{
sf("%d%d",&x,&y);
if(judge(x,y)) pf("SUCCESS\n");
else pf("FAIL\n");
}
getchar();
}
return 0;
}

D - Wireless Network的更多相关文章

  1. [并查集] POJ 2236 Wireless Network

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 25022   Accepted: 103 ...

  2. POJ 2236 Wireless Network(并查集)

    传送门  Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 24513   Accepted ...

  3. poj 2236:Wireless Network(并查集,提高题)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 677 ...

  4. 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 ...

  5. Wireless Network

    Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 19626 Accepted: 8234 De ...

  6. POJ 2236 Wireless Network (并查集)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 18066   Accepted: 761 ...

  7. POJ 2236 Wireless Network (并查集)

    Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...

  8. Wireless Network(POJ 2236)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 20724   Accepted: 871 ...

  9. POJ - 2336 Wireless Network

    Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...

  10. POJ2236 Wireless Network 并查集简单应用

    Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...

随机推荐

  1. Android GUI之View测量

    在上篇文章(http://www.cnblogs.com/jerehedu/p/4607599.html#gui)中,根据源码探索了View的绘制过程,过程有三个主要步骤,分别为测量.布局.绘制.系统 ...

  2. HOW TO REPLACE ALL OCCURRENCES OF A CHARACTER IN A STD::STRING

    From: http://www.martinbroadhurst.com/replacing-all-occurrences-of-a-character-in-a-stdstring.html T ...

  3. sprintf将CString转换成char[]

      在MFC中使用sprintf()函数将CString转换成char[]时,char[]只接受第一个字符 使用的是VS2008 CString name;dbName="test" ...

  4. 【T05】套接字接口比XTI_TLI更好用

    1.用于网络编程的API接口有两种: Berkeley套接字 XTL 2.套接字是加州大学伯克利分校为其Unix操作系统版本开发的,TLI是AT&T(贝尔实验室)为Unix系统V3.0开发的 ...

  5. Nginx——使用 Nginx 提升网站访问速度【转载+整理】

    原文地址 本文是写于 2008 年,文中提到 Nginx 不支持 Windows 操作系统,但是现在它已经支持了,此外还支持 FreeBSD,Solaris,MacOS X~ Nginx(" ...

  6. C#串口SerialPort常用属性方法

    SerialPort(): //属性 .BaudRate;获取或设置波特率 .BytesToRead;得到 接收到数据的字节数 .BytesToWrites;得到送往串口的字节数 .DataBits; ...

  7. PL/SQL学习笔记之异常

    一:异常 程序执行过程中出现错误情况被称为异常,主要有两种类型的异常: 系统定义的异常 用户定义的异常 二:系统定义的异常 Exception Oracle Error SQLCODE 描述 ACCE ...

  8. 阿里云Logtail 快速诊断工具

    当日志采集发生异常时,您可以通过Logtail自助检测工具查看客户端是否存在异常情况,根据工具提示快速定位并解决问题.   说明 本工具目前仅支持Linux系统的服务器. 准备工作 下载检测工具脚本. ...

  9. Java中apache下面FtpClient主动模式和被动模式

    最近在做ftp文件上传的时候,开发测试环境上传都没有问题,但是在开发环境缺无法上传,但是也没有报错,纠结了老久.最后看到网上有说FtpClient有主动模式和被动模式之分,然后就解决了. FTPCli ...

  10. 实例展示elasticsearch集群生态,分片以及水平扩展.

    elasticsearch用于构建高可用和可扩展的系统.扩展的方式可以是购买更好的服务器(纵向扩展)或者购买更多的服务器(横向扩展),Elasticsearch能从更强大的硬件中获得更好的性能,但是纵 ...