来源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. ckeditor 上传图片解决跨域问题

    前后端分离ckeditor跨域问题处理 这个跨域问题很常见,特别是前后端分离的情况,IP地址不同导致了页面跨域,具体原因大多是因为前端ifame问题 分析 ckeditor插件里config.js需要 ...

  2. CentOS7下 让Docker pull命令使用squid做http代理拉取目标镜像仓库的镜像

    场景,如下图所示: 服务器B具有两个网卡,分别和服务器A和服务器C互通,这里想要在服务器C上借助服务器B作为桥梁,拉取镜像仓库服务器A上的镜像. 思路也很简单,在服务器上搭建HTTP代理服务,服务器C ...

  3. hihocoder第238周:杨氏矩阵的个数

    题目链接 问题描述 给定一个N行M列的矩阵,往里面填入$1-N\times M$个数字,使得这个矩阵每行.每列都满足递增.问:有多少种填法? 问题分析 这个问题很难,如果能够直接想到,那就是天才了. ...

  4. 【Vegas原创】查询SQL Server更改记录的语句

    指定数据库,然后: select Name,Create_date,Modify_Date from sys.objects where type in ('U','P', 'V','F', 'TR' ...

  5. Atitit web remote远程调试的原理attilax总结

    Atitit web remote远程调试的原理attilax总结 Jvm是vm打开一个debug port,然后ide先连接..然后执行url,就会vm会与ide沟通.. Php的xdebug po ...

  6. 无意识(无知)-->有意识-->进入潜意识-->无意识(本能状态)

    无意识(无知)-->有意识-->进入潜意识-->无意识(本能状态) 1. 从“无意识-->有意识”的两个重要内容是“反省”+“要努力学习”,估计有80%的人无法跨过这一步 2. ...

  7. Linux给普通用户增加ssh权限

    //1,创建用户 useradd name //2,修改密码 passwd name //3,修改ssh配置文件,在最后一行添加AllowUsers name vi /etc/ssh/sshd_con ...

  8. 【Tomcat】Tomcat 系统架构与设计模式,第 2 部分: 设计模式分析

    这个分为两个部分的系列文章研究了 Apache Tomcat 服务器的系统架构以及其运用的很多经典设计模式.第 1 部分 分析了 Tomcat 的工作原理,第 2 部分将分析 Tomcat 中运用的许 ...

  9. Swift 4迁移总结:喜忧参半,新的起点

    Swift 4迁移总结:喜忧参半,新的起点 每日一篇优秀博文 这次Swift 3 到 4 的迁移代码要改动的地方比较少,花了一个下午的时间就完成了迁移.Swift 把原来 4.0 的目标从 ABI 稳 ...

  10. Vue中使用ECharts画散点图加均值线与阴影区域

    [本文出自天外归云的博客园] 需求 1. Vue中使用ECharts画散点图 2. 在图中加入加均值线 3. 在图中标注出阴影区域 实现 实现这个需求,要明确两点: 1. 知道如何在vue中使用ech ...