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 判断两台计算机是否联通 ...
随机推荐
- echarts渲染一个风向图
今天给大家说一个用echarts渲染一个风向图,这里图上其实有三个要素,风向,风级和能见度,主要还是讲讲代码里面的坑 1.风向图标方向修改以及设置 var ownData = echarts.util ...
- c#和c++的运算符优先级
闲来无聊乱写代码.发现基础的东西有的时候也非常的抽象.不信?那来看看下面这条语句: ; ; j = i = -i++; 如果上述代码是vc++代码,那么输出结果是: i=- j=- 请按任意键继续. ...
- Azure降价辣么多,省下的预算该怎么花?
那么 Azure 产品创新以及服务完善到底体现在何处呢?以下最新发布内容也许可以告诉你答案. ◆ ◆ ◆ Power BI Embedded 让应用中的数据更加生动 Microsoft Power B ...
- Azure 进阶攻略 | 文件完整性,你打算如何证明?
假设你是一位独立软件开发者,通过自己的网站提供软件下载.网站完全托管在 Azure 中,并且软件下载也是通过 Azure Blob 存储和 Azure CDN 服务提供的. 这做法真不错,不需要自己管 ...
- mysql自增ID
InnoDB引擎的表,执行清空操作之后,表的auto_increment值不会受到影响:一旦重启MySQL,auto_increment值将变成1. MyISAM引擎的表,执行清空操作之后,表的aut ...
- struts2表单提交Date数据无法接收
问题:在Struts2环境下,提交含有Date类型数据表单,但是在action中没有接收到:String就可以直接接收到: --网络搜索后,说Struts2可以自己转,但是目前没发现有: 然后在狂搜, ...
- 2018.9.8pat秋季甲级考试
第一次参加pat考试,结果很惨,只做了中间两道题,还有一个测试点错误,所以最终只得了不到50分.题目是甲级练习题的1148-1151. 考试时有些紧张,第一题第二题开始测试样例都运行不正确,但是调试程 ...
- jemter实战
业务流梳理,需要实现的内容,含jdbc和正则表达式,和取值 1. 登录用户 2. 获取一个未分配的订单,判断是否是未分配 3. 获取配货单号 4. 分配配货单 5. 查询已分配的配货单 6. 查询包裹 ...
- centos 7jenkin+git 安装
jenkins+git配置 背景:用git管理源代码,所以需要jenkins安装Git Plugin插件配置 准备: 1.linux环境git客户端 2.jenkins环境 + git plugin插 ...
- PHP获取当前页面完整路径URL
//PHP获取当前页面完整路径URL 1 <?php function getFullUrl(){ # 解决通用问题 $requestUri = ''; if (isset($_SERVER[' ...