D - Wireless Network
来源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:
- "O p" (1 <= p <= N), which means repairing computer p.
- "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的更多相关文章
- [并查集] 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 ...
- Wireless Network
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 19626 Accepted: 8234 De ...
- 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 ...
随机推荐
- C++中int与string的相互转换【转】
一.int转string 1.c++11标准增加了全局函数std::to_string: string to_string (int val); string to_string (long val) ...
- 解密gzip压缩的网页数据流(转)
因为采集某个网页遇到问题,一直无法获取页面数据. 经过一番排查,发现该网站会检查客户端的Header信息,如果遇到不明确的Header信息就直接否定,返回0数据. 如果Header信息正确,就会返回经 ...
- pytorch中检测分割模型中图像预处理探究
Object Detection and Classification using R-CNNs 目标检测:数据增强(Numpy+Pytorch) - 主要探究检测分割模型数据增强操作有哪些? - 检 ...
- Excel分组快速自动填充编号
在Excel自动填充很简单,但如果按分组等条件进行填充就有点麻烦了 说麻烦可能是你并没有搞清楚到底如何才能实现你的需求 下图是客户提供的Excel数据,我需要将下面的数据导入到数据库中,因为客户在 ...
- MongoDB 进程控制系列一:查看当前正在执行的进程
1:查看MongoDB当前正在做哪些操作? db.currentOp() 等同于: db.$cmd.sys.inprog.findOne() 2:查看当前有多少个连接? db.serverStatus ...
- Spring中通过Annotation来实现AOP
一.Spring配置文件 <!--通过@AspectJ注解的形式来使用Spring AOP,强制使用CGLIB代理--> <aop:aspectj-autoproxy proxy-t ...
- eclipse spring 配置文件xml校验时,xsd报错
1.情景展示 eclipse中,spring配置文件报错信息如下: 配置文件头部引用信息为: <?xml version="1.0" encoding="UTF ...
- [转]抛弃jQuery,使用原生JavaScript
原文链接 Document Ready 事件 在jQuery中,document.ready可以让代码在整个文档加载完毕之后执行: $(document).ready(function() { // ...
- Non-negative Matrix Factorization 非负矩阵分解
著名的科学杂志<Nature>于1999年刊登了两位科学家D.D.Lee和H.S.Seung对数学中非负矩阵研究的突出成果.该文提出了一种新的矩阵分解思想――非负矩阵分解(Non-nega ...
- MySQL权限和用户安全
MySQL访问控制分为两个阶段阶段1: 检查用户是否可以连接到mysql server 阶段2: 检查用户执行的sql是否已经被授权