POJ A-Wireless Network
http://poj.org/problem?id=2236
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
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 <iostream>
#include <string.h>
using namespace std; int f[1010];
int N, d;
bool rep[1010];
int q, p, n; int st[1010];
int en[1010]; void init() {
for(int i = 1; i <= N; i ++) {
f[i] = i;
rep[i] = false;
}
} int Find(int x) {
if(f[x] != x) f[x] = Find(f[x]);
return f[x];
} void Merge(int x, int y) {
int fx = Find(x);
int fy = Find(y);
if(fx != fy)
f[fx] = fy;
} int main() {
scanf("%d%d", &N, &d);
init();
for(int i = 1; i <= N; i ++)
scanf("%d%d", &st[i], &en[i]); int f1, f2;
char op;
while(~scanf("%c", &op)) {
if(op == 'O') {
scanf("%d", &n);
rep[n] = true;
for(int i = 1; i <= N; i ++) {
if(i != n && rep[i] && (en[i] - en[n]) * (en[i] - en[n]) + (st[i] - st[n]) * (st[i] - st[n]) <= d * d) {
f1 = Find(n);
f2 = Find(i);
f[f1] = f2;
}
}
}
else if(op == 'S'){
scanf("%d%d", &q, &p);
f1 = Find(p);
f2 = Find(q); if(f1 == f2) printf("SUCCESS\n");
else printf("FAIL\n");
}
}
return 0;
}
POJ A-Wireless Network的更多相关文章
- 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 - 2336 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: 24513 Accepted ...
- POJ 2236 Wireless Network (并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 18066 Accepted: 761 ...
- 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 ...
- [ An Ac a Day ^_^ ] [kuangbin带你飞]专题五 并查集 POJ 2236 Wireless Network
题意: 一次地震震坏了所有网点 现在开始修复它们 有N个点 距离为d的网点可以进行通信 O p 代表p点已经修复 S p q 代表询问p q之间是否能够通信 思路: 基础并查集 每次修复一个点重新 ...
随机推荐
- Shell编程学习之Shell编程基础(一)
这篇随笔将要介绍关于Shell编程的基本知识,这些将会在假设你已经熟悉了Linux系统和命令行的基本知识. 构建基本脚本 你应该了解或熟悉使用Shell命令行了,但是只是使用Shell命令行的命令,有 ...
- PHP调试小错误汇总
1.中文显示乱码 解决:加上header('Content-type:text'); 2.Unable to find the wrapper "https 解决:到php.ini中把ext ...
- ajaxfileup.js
<img id="tinyPic" class="user-icon" :src="headPortrait"><inpu ...
- Linux下vim操作的一些使用技巧
以下均为个人在编程时对vim编辑器的一些心得,大神请指点,新手可以看过来 1.多文本编辑 vim -On/-on filename_1 … filename_n 如上所示,在要编辑的文件名前加上“-O ...
- JavaScript - 库 jQuery
测试 JavaScript 框架库 - jQuery 引用JQuery 如需测试JavaScript库,您需要在网页中引用它. 为了引用某个库,请使用<script>标签,其src属性设置 ...
- 【PHP项目】【Smarty】Smarty截取字符串方法truncate
smarty truncate 截取字符串 //在sql中truncate是删除表格(truncate是只删除内容,delete彻底删除)从字符串开始处截取某长度的字符,默认的长度为80指定第二个参 ...
- python爬虫:爬取猫眼TOP100榜的100部高分经典电影
1.问题描述: 爬取猫眼TOP100榜的100部高分经典电影,并将数据存储到CSV文件中 2.思路分析: (1)目标网址:http://maoyan.com/board/4 (2)代码结构: (3) ...
- B-树 动机与结构
Ps.我们遵循从感性到理性的认知顺序来逐步探索B-树的奥秘,之前经常说的value这里用key(关键码)指代,因为可能存的是字符串,说是value就不合适了. (多图预警!!!建议在WI-FI下观看) ...
- python基础之数据类型与变量patr2
一.元素分类 有如下值集合 [11,22,33,44,55,66,77,88,99,90...],将所有大于 66 的值保存至字典的第一个key中,将小于 66 的值保存至第二个key的值中. 即: ...
- 1 Mongodb安装
1.NoSQL简介 NoSQL,全名Not Only SQL,指的是非关系型的数据库 随着访问量的上升,网站的数据库性能出现了问题,于是NoSQL被设计出来了 优点.缺点 优点 高扩展性 分布式计算 ...