POJ2236 Wireless Network 并查集
水题
#include<cstdio>
#include<cstring>
#include<queue>
#include<set>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL;
typedef pair<int,int>pii;
const int N=1e3+;
const int INF=0x3f3f3f3f;
pii o[N];
bool vis[N];
int fa[N];
int find(int x){
return fa[x]==x?x:fa[x]=find(fa[x]);
}
int dis(int i,int j){
return (o[i].first-o[j].first)*(o[i].first-o[j].first)+(o[i].second-o[j].second)*(o[i].second-o[j].second);
}
int main(){
int n,d,x,y;
scanf("%d%d",&n,&d);
for(int i=;i<=n;++i)
scanf("%d%d",&o[i].first,&o[i].second),fa[i]=i;
char s[];
while(~scanf("%s",s)){
if(s[]=='O'){
scanf("%d",&x);
if(vis[x])continue;
for(int i=;i<=n;++i){
if(!vis[i]||dis(x,i)>d*d)continue;
int u=find(x),v=find(i);
if(u!=v)fa[u]=v;
}
vis[x]=true;
}
else {
scanf("%d%d",&x,&y);
x=find(x),y=find(y);
if(x==y)printf("SUCCESS\n");
else printf("FAIL\n");
}
}
return ;
}
POJ2236 Wireless Network 并查集的更多相关文章
- POJ2236 Wireless Network 并查集简单应用
Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...
- POJ 2236 Wireless Network (并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 18066 Accepted: 761 ...
- Wireless Network 并查集
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- poj 2236 Wireless Network (并查集)
链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...
- POJ 2236 Wireless Network [并查集+几何坐标 ]
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- poj-2236 Wireless Network &&poj-1611 The Suspects && poj-2524 Ubiquitous Religions (基础并查集)
http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由 ...
- poj2236 Wireless Network(并查集直接套模板
题目地址:http://poj.org/problem?id=2236 题目大意:n台电脑都坏了,只有距离小于d且被修好的电脑才可以互相联系,联系可传递.输入n和d,n个点的坐标x y.两个操作:O ...
- POJ-2236 Wireless Network 顺便讨论时间超限问题
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 26131 Accepted: 108 ...
- [LA] 3027 - Corporative Network [并查集]
A very big corporation is developing its corporative network. In the beginning each of the N enterpr ...
随机推荐
- shell awk
#!/bin/bash # ;i<=;i++)); # do # c1=`shuf -i - -n ` #生成随机数 # c2=`shuf -i - -n ` # c3=`shuf -i - - ...
- javascript之变量、作用域、作用域链
一.变量 javascript的变量是松散类型的,所谓松散类型就是说定义的变量可以用来保存任何类型的数据.定义变量时要使用var操作符后面跟变量名.这里的var是一个关键字,如果定义变量时省略了var ...
- SQL技巧之分类汇总
数据表结构username type numaaaa 玉米 1212aaaa 玉米 212bbb 小麦 2323bbb .... 只有两种产品 玉米和小麦,玉米价格1.5,小麦价格 ...
- 使用jQuery.FileUpload插件和Backload组件裁剪上传图片
□ 思路 1.自定义控制器继承Backload的默认控制器BackloadController2.自定义一个jQuery File Upload初始化js文件,使用自定义控制器的方法3.在视图页面调用 ...
- 学会Twitter Bootstrap不再难
Twitter Bootstrap 3.0 是对其过去的重大改变,现在它更偏向于移动应用的框架,并且宣称是最好的web设计css框架之一,的确如此. 可能有人曾经使用过Twitter Bootstra ...
- ElasticSearch入门-搜索如此简单
搜索引擎我也不是很熟悉,但是数据库还是比较了解.可以把搜索理解为数据库的like功能的替代品.因为like有以下几点不足: 第一.like的效率不行,在使用like时,一般都用不到索引,除非使用前缀匹 ...
- 使用Yeoman搭建 AngularJS 应用 (3) —— 让我们搭建一个网页应用
原文地址:http://yeoman.io/codelab/setup.html 与Yeoman的交互大多数是通过命令行.在苹果机器需要使用Terminal应用,在Linux使用shell.如果使用W ...
- caffe之(四)全连接层
在caffe中,网络的结构由prototxt文件中给出,由一些列的Layer(层)组成,常用的层如:数据加载层.卷积操作层.pooling层.非线性变换层.内积运算层.归一化层.损失计算层等:本篇主要 ...
- call()和apply()的区别
var a = function(a,b){ console.log(a+b); }, b = { c:5, d:3 }; a.call(b,1,2); a.apply(b,[1,2]); a.cal ...
- portlet初学习及HelloWorld例子
1. 在myeclipse中新建一个web project,在src中新建如下类: package com.yoyo.portlet; import java.io.IOException; impo ...