POJ:2236-Wireless Network
Wireless Network
Time Limit: 10000MS Memory Limit: 65536K
Total Submissions: 34265 Accepted: 14222
Description
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:
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
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
解题心得:
- 题意就是有n台电脑,每台电脑有一个坐标,它只可以联系和它距离在d内的电脑,现在每台电脑都是坏的,有两种操作,第一种就是维修某台电脑,第二种就是询问两台电脑是否可以通信。
- 时间给得很足啊,整整十秒,也就很简单了,每次暴力维护可以保持相互通信的电脑
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1010;
int father[maxn],n,d;
bool vis[maxn];
struct Pos {
int x,y;
}p[maxn];
void init() {
scanf("%d%d",&n,&d);
for(int i=1;i<=n;i++)
father[i] = i;
for(int i=1;i<=n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
}
int find(int x) {
if(father[x] == x)
return x;
return father[x] = find(father[x]);
}
void merge(int x,int y) {
int fx = find(x);
int fy = find(y);
father[fx] = fy;
}
void fix(int pos) {
vis[pos] = true;
for(int i=1;i<=n;i++) {
if(vis[i]) {
int d2 = (p[i].x-p[pos].x)*(p[i].x-p[pos].x) + (p[i].y-p[pos].y)*(p[i].y-p[pos].y);
if(d2 <= d*d) {
if(find(i) != find(pos)) {
int fi = find(i);
for(int j=1;j<=n;j++) {
if(father[j] == fi)
merge(j,pos);
}
}
}
}
}
}
int main(){
init();
char s[5];
while(scanf("%s",s) != EOF) {
int pos,a,b;
if(s[0] == 'O') {
scanf("%d",&pos);
if(vis[pos])
continue;
else
fix(pos);
} else {
scanf("%d%d",&a,&b);
if(vis[a] && vis[b] && find(a) == find(b))
printf("SUCCESS\n");
else
printf("FAIL\n");
}
}
return 0;
}
POJ:2236-Wireless Network的更多相关文章
- 【POJ】2236 Wireless Network
题目链接:http://poj.org/problem?id=2236 题意:给你n台计算机的坐标.d是可通信的最大距离.有两个操作. 1.O p 表示修复计算机p. 2.S p q表示询问pq是否能 ...
- 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 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...
- poj 2236 Wireless Network 【并查集】
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 16832 Accepted: 706 ...
- 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(并查集)
传送门 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: 18066 Accepted: 761 ...
- poj 2236 Wireless Network (并查集)
链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...
随机推荐
- Sharepoint 2013企业内容管理学习笔记(二) 全自动化内容管理
全自动化内容管理 所谓全自动化内容管理啊,其实对于用户来说,就更简单便捷有爱了,用户只需要把文件上传到部门网站的放置库中,文件就会快速自动躺到企业记录中心的某个归档记录库了,怎么样,很方便,有没有,很 ...
- 转:ArcGIS10.1正式版安装与破解
一.准备文件 ArcGIS10.1安装包:ArcGIS_Desktop_10.1_129026(en) 认证服务:Pre-release_license_manager 注册机:arcgis10.1K ...
- C++ Knowledge series Template & Class
Function Function is composed of name, parameter (operand, type of operand), return value, body with ...
- ARouter使用随记
官方文档地址 其他配置 1.创建一个config.gradle ext{ isDebug = false //false:作为Lib集成存在, true:作为application组件存在 andro ...
- python异常处理、断言
异常处理基本语法 捕获异常 try: 语句1 语句2 ... except ERRNAME as e: print(e) #尝试执行语句,捕获到ERRNAME异常时打印异常信息e 捕获多个异常 try ...
- Struts2_用DomainModel接收参数
用域模型接收参数 User类 package com.bjsxt.struts2.user.model; public class User { private String name; privat ...
- Eclipse JSP 页面设置 charset=UTF-8
windows —> Preferences —> 搜索框中输入:JSP,设置如下:
- Java—多态
多态——对象的多种形态(继承是多态实现的基础) 引用多态:父类的引用可以指向本类的对象:父类的引用可以指向子类的对象 方法多态:创建本类对象时,调用的方法为本类方法:创建子类对象时,调用的方法为子类重 ...
- ansible使用4-Playbook Roles and Include Statements
task include --- # possibly saved as tasks/foo.yml - name: placeholder foo command: /bin/foo - name: ...
- MySQL入门很简单: 8查询数据
1. 查询语句语法 SELECT 属性列表 FROM 表名和视图列表 [WHERE 条件表达式1] [GROUP BY 属性名1 [HAVING t条件表达式2]] [ORDER BY 属性名2 [A ...