poj 2236
Description
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
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
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 Code
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define pi acos(-1.0)
#define mj
#define inf 0x3f3f3f
typedef double db ;
typedef long long ll;
using namespace std;
const int N=1e3+;
const int mod=1e9+;
int f[N],dis[N],d;
bool has[N];
pair<int ,int > po[N];
vector<int> e[N];
int find(int x)
{
return f[x]==x?x:f[x]=find(f[x]);
}
void unit(int x,int y)
{
int fx=find(x),fy=find(y);
if(fx!=fy)
f[fx]=fy;
}
int main()
{
int n,d;
scanf("%d%d",&n,&d);
for(int i=;i<=n;i++){
f[i]=i;
int x,y;
scanf("%d%d",&x,&y);
po[i].first=x;
po[i].second=y;
}
for(int i=;i<n;i++){
for(int j=i+;j<=n;j++){
int x1=po[i].first,y1=po[i].second,x2=po[j].first,y2=po[j].second;
if((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)<=d*d) {e[i].push_back(j);e[j].push_back(i);}
}
}
char s[];
while(scanf("%s",s)==){
if(s[]=='O'){
int x;
scanf("%d",&x);
has[x]=;
for(int i=;i<e[x].size();i++){
int v=e[x][i];
if(has[v]){
unit(v,x);
}
}
}
else
{
int x,y;
scanf("%d%d",&x,&y);
// printf("%d find:%d %d find:%d\n",x,find(x),y,find(y));
if(find(x)==find(y)) puts("SUCCESS");
else puts("FAIL");
}
}
return ;
}
poj 2236的更多相关文章
- POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集
POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...
- 【并查集】模板 + 【HDU 1213、HDU 1232、POJ 2236、POJ 1703】例题详解
不想看模板,想直接看题目的请戳下面目录: 目录: HDU 1213 How Many Tables[传送门] HDU 1232 畅通工程 [传送门] POJ 2236 Wireless Network ...
- poj 2236【并查集】
poj 2236 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical t ...
- poj 2236 Wireless Network (并查集)
链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...
- (并查集) Wireless Network --POJ --2236
链接: http://poj.org/problem?id=2236 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- Poj(2236),简单并查集
题目链接:http://poj.org/problem?id=2236 思路很简单,傻逼的我输出写成了FALL,然后遍历的时候for循环写错了,还好很快我就Debug出来了. #include < ...
- [并查集] 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: 16065 Accepted: 677 ...
- POJ 2236:Wireless Network
描述 n台电脑,如果两台电脑间的距离的d范围内,则两台电脑能够连通. 如果AB连通,BC连通,则认为AC连通. 已知电脑台数N,最大距离d,以及每个电脑的坐标.有如下两种操作: O i 表示修复编号为 ...
- POJ 2236 Wireless Network(并查集)
传送门 Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 24513 Accepted ...
随机推荐
- Bootstrap每天必学之导航条
http://www.jb51.net/article/75534.htm Bootstrap每天必学之导航条,本文向大家讲解了多种多样的导航条,以及导航条中元素的实现方法,感兴趣的小伙伴们可以参考一 ...
- iOS 之 const
const int a与 int const a一样. const int *a ;//指针可以修改,指向常整形的指针 int* const a;// 常指针, int* 作为一个整体被限制, 所以指 ...
- @pathvariable 注解
1.4. @PathVariable 注解 带占位符的 URL 是 Spring3.0 新增的功能,该功能在SpringMVC 向 REST 目标挺进发展过程中具有里程碑的意义 通过 @PathVar ...
- Linux下的文件目录结构详解
Linux下的文件目录结构详解 / Linux文件系统的上层根目录 /bin 存放用户可执行的程序 /boot 操作系统启动时所需要的文件 /dev 接口设备文件目录,例如:had表示硬盘 /etc ...
- --@angularJS--指令与控制器之间较复杂的交互demo2
1.index.html: <!DOCTYPE HTML><html ng-app="app"><head> <title>c ...
- 高斯RBF核函数中Sigma取值和SVM分离面的影响
1:高斯RBF核函数的定义 k(x) = exp(-x^2/(2×sigma)) 在MATLAB中输入一下代码:ezsurf('exp(-x^2/(2*sigma^2))'); 在GOOGLE中输入“ ...
- Clojure发音
Clojure的发音和单词closure是一样的.Clojure之父是这样解释Clojure名字来历的 “我想把这就几个元素包含在里面: C (C#), L (Lisp) and J (Java). ...
- 使用FileReader实现前端图片预览
在FileReader出现之前,前端的图片预览是这样实现的:把本地图片上传到服务器,服务器把图片地址返回,并把它替换到图片元素的src属性. 这种方法的缺点是:必须要先把图片上传到服务器.那么问题来了 ...
- 【Ionic+AngularJS 开发】之『个人日常管理』App(二)
准备工作 资源 预装工具 安装bower npm install -g bower 安装ngCordova bower install ngCordova (*由于网络获取资源的原因,后面几次建项目后 ...
- java 文件操作 读取txt文本(兄弟常开心)
测试一下读取文本的另一种方法:该方法只使用一个类读取了文件 注意:buffer和read方法中读取指定长度的一致 package com.swust; import java.io.*; /* * 数 ...