poj 2236 Wireless Network 【并查集】
Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 16832 | Accepted: 7068 |
Description
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
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
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
注意要区分修过的和没修过的
代码:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define M 1005
#define LL __int64 struct node{
int x, y;
}s[M];
int map[M][M], fat[M], vis[M]; int f(int x){
if(fat[x] != x) fat[x] = f(fat[x]);
return fat[x];
} int main(){
int n, d;
scanf("%d%d", &n, &d);
int i, j;
d*=d;
for(i = 1; i <= n; i ++){
scanf("%d%d", &s[i].x, &s[i].y);
map[i][i] = 0;
for(j = i-1; j> 0; j --){
map[j][i] = map[i][j] = (s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y);
// printf("%d..map(%d, %d)\n", map[i][j], i, j);
}
}
char ss[2];
int a, b;
memset(vis, 0, sizeof(vis));
for(i = 1; i <= n; i++) fat[i] = i;
while(scanf("%s", ss) == 1){
if(ss[0] == 'O'){
scanf("%d", &a);
vis[a] = 1;
for(i = 1; i <= n; i ++){
if(vis[i]&&map[a][i] <= d&&i != a){
int x = f(a); int y = f(i);
if(x != y) fat[x] = y;
}
}
}
else{
scanf("%d%d", &a, &b);
int x = f(a); int y = f(b);
if(vis[a]&&vis[b]&&x == y) printf("SUCCESS\n");
else printf("FAIL\n");
}
}
return 0;
}
poj 2236 Wireless Network 【并查集】的更多相关文章
- POJ 2236 Wireless Network (并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 18066 Accepted: 761 ...
- 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 1703 Find them, Catch them 并查集
POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...
- [并查集] 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(并查集)
传送门 Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 24513 Accepted ...
- POJ 2236 Wireless Network (并查集)
Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...
- [ An Ac a Day ^_^ ] [kuangbin带你飞]专题五 并查集 POJ 2236 Wireless Network
题意: 一次地震震坏了所有网点 现在开始修复它们 有N个点 距离为d的网点可以进行通信 O p 代表p点已经修复 S p q 代表询问p q之间是否能够通信 思路: 基础并查集 每次修复一个点重新 ...
随机推荐
- magento批量上传产品
Step1:表格仔细检查无误后,将准备好的图片上传至 media/import中.如果使用专用的图片服务器,把图片上传到服务器上,当然表格中的图片地址要做相应的修改. Step2:然后,登陆Magen ...
- 【ASP.NET MVC】 路由机制:命名路由
首先看一下命名路由和没有命名的差别: 命名路由: routes.MapRoute( name: "Test", // Route name url: "code/p/{a ...
- java.lang.ClassCastException: xut.bookshop.entity.User_$$_javassist_3 cannot be cast to javassist.util.proxy.Proxy
报错信息 java.lang.ClassCastException: xut.bookshop.entity.User_$$_javassist_3 cannot be cast to javassi ...
- JSP2 自定义标签
实现步骤 实现自定义标签的处理类继承javax.servlet.jsp.tagext.SimpleTagSupport,并重写doTag方法 建立标签库配置文件 在jsp中使用自定义标签 一个简单的标 ...
- sql 预编译 in
sql : "select * from json where id in (:paramName)"; 在使用Hibernate时,sql in的预编译语句为query.setP ...
- UML整体概括
UML (Unified Modeling Language)为面向对象软件设计提供统一的.标准的.可视化的建模语言.适用于描述以用例为驱动,以体系结构为中心的软件设计的全过程. UML的定义包括UM ...
- 【Splay】洛谷3372 【模板】线段树 1
Splay区间加,询问区间和. #include<cstdio> #include<iostream> #include<cstring> #include< ...
- 【线段树区间合并】BZOJ1593-[Usaco2008 Feb]Hotel 旅馆
好无聊,以前写过没什么好讲的,水过.戳 #include<iostream> #include<cstdio> #include<cstdlib> #define ...
- http请求 url 传递参数(特殊字符)解决方法
有些符号在URL中是不能直接传递的,如果要在URL中传递这些特殊符号,那么就要使用他们的编码了.下表中列出了一些URL特殊符号及编码 十六进制值 1. + URL 中+号表示空格 %2B ...
- 鹦鹉学舌1——C语言初学者百题大战之三
#include<stdio.h> int main() { int a; scanf("%d",&a); printf("%d",a-a+ ...