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 ...
随机推荐
- [转]优化PHP程序的方法
1. If a method c++an be static, declare it static. Speed improvement is by a factor of 4. 如果一个方法可静态化 ...
- 出力csv
public static void ExportResultLog(System.Data.DataTable dt, string fileName, string path) { if (!Sy ...
- Memcached服务器安装、配置、使用详解
管理memcached服务 启动Memcached 一般情况下,简单地可以使用类似如下形式,启动Memcached服务: /usr/local/bin/memcached -d -m 64 -I 20 ...
- NodeJS+ExpressJS+SocketIO+MongoDB应用模板
OS:Win8.1 with update 关键字:NodeJS,ExpressJS,SocketIO,MongoDB. 1.源代码下载:https://github.com/ldlchina/ESM ...
- MVC-各种传值方式
[转自]:QLeelulu示例一:ViewData传值.HomeController.cs Co de: public ActionResult Index(){ ViewData[" ...
- 创建Mysql
CREATE DATABASE IF NOT EXISTS yiya DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
- CODEVS 3000公路修建问题
题目描述 Description OI island是一个非常漂亮的岛屿,自开发以来,到这儿来旅游的人很多.然而,由于该岛屿刚刚开发不久,所以那里的交通情况还是很糟糕.所以,OIER Associat ...
- vs2015Update2的一个坑
最近更新了vs2015到update2,然后,蛋疼的事情就来了. 首先发现QT不能用了 boost编译也出问题了 查找了2天,发现问题所在,在于windows sdk更新 10.0.10586.0 了 ...
- Global中的事件执行顺序
The Global.asax file, sometimes called the ASP.NET application file, provides a way to respond to ap ...
- ZOJ 2750 Idiomatic Phrases Game(Dijkstra)
点我看题目 题意 : 给定一本字典,字典里有很多成语,要求从字典里的第一个成语开始,运用字典里的成语变到最后一个成语,变得过程就是成语接龙,后一个成语的第一个字必须有前一个成语的最后一个字相等,给定的 ...