来源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. 在DevExpress程序中使用内置的图标构建美观的界面元素【转】

    https://www.cnblogs.com/wuhuacong/p/6217012.html 在我们一般的程序中,为一般的界面元素添加一定的图标展示,有助于提升界面的整体的美观.结合排版布局,以及 ...

  2. 关于#progma comment 中库文件相对路径问题

    最近做一个验证程序的对话框编程,因为里面要要用到静态链接库,所以就稍微的学习了下静态链接库知识,学习的过程中感觉到了自己所了解的东西实在是少的可怜,更加坚定了自己要更加上进的决心,要把以前所丢掉的都给 ...

  3. CentOS7 下 keepalived 的安装和配置

    安装前准备:yum -y install gcc gcc-c++ autoconf automake make yum -y install zlib zlib-devel openssl opens ...

  4. Android批量图片加载经典系列——使用LruCache、AsyncTask缓存并异步加载图片

    一.问题描述 使用LruCache.AsyncTask实现批量图片的加载并达到下列技术要求 1.从缓存中读取图片,若不在缓存中,则开启异步线程(AsyncTask)加载图片,并放入缓存中 2.及时移除 ...

  5. Redis深入之对象

    Redis对象系统 前面介绍了Redis用到的全部主要数据结构,如简单动态字符串(SDS).双端链表.字典.压缩列表.整数集合等 Redis并没有直接使用这些数据结构来实现键值对数据库.而是基于这些数 ...

  6. python Image resize 对iOS图片素材进行2X,3X处理

    通常在iOS上开发使用的图片素材1x,2x,3x三种 下面利用python Image 库 resize函数,由一个大图,自动生成1x,2x,3x的素材照片: 1. 首先你的python环境要安装有I ...

  7. llvm Array Bounds Check Elimination

    http://www.knosof.co.uk/vulnerabilities/arraybnd.html http://www.cs.utsa.edu/dmz/techrep/2010/CS-TR- ...

  8. 【转】一次SpringMVC+ Mybatis 配置多数据源经历

    需求 现在在维护的是学校的一款信息服务APP的后台,最近要开发一些新功能,其中一个就是加入学校电影院的在线购票.在线购票实际上已经有一套系统了,但是是外包给别人开发的,我们拿不到代码只能拿到数据库,并 ...

  9. windows IOCP入门的一些资料

    最近需要看一个中间件的IOCP处理模块,需要了解这方面的知识 https://www.codeproject.com/articles/13382/a-simple-application-using ...

  10. dos命令dir查找文件的用法及实例

      功能:显示目录命令 格式:dir[盘符][路径][/W][/P][/L][/O:排序][/A:属性][/S] 参数介绍: /W -- 以宽行排列方式显示. /P -- 每显示满一屏停顿一下,待用户 ...