POJ - 2336 Wireless Network
Description
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 O
O
O
S
O
S
Sample Output FAIL
SUCCESS
题目链接:http://poj.org/problem?id=2236
******************************************
题意:给你n台电脑,然后给出给各电脑坐标,距离不超过d才可以沟通。一开始电脑都是坏的,o操作代表修电脑,s操作判断x与y是否可以联通。
分析:s查询的时候就是简单的并查集,但对于修复更新的时候要注意距离的判断,符合要求的才可以。
一开始FAIL 写成了FALL,唉
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<algorithm>
#include<time.h>
using namespace std; #define N 1550
#define INF 0x3f3f3f3f int Father[N]; struct node
{
int x,y,v;
}a[N];///保存所有的村庄,v标记是否已经修复 int Find(int x)
{
if(x != Father[x])
x=Find(Father[x]);
return x;
} int Len(node a,node b)///求两个村庄的距离
{
int x=b.x-a.x;
int y=b.y-a.y;
return x*x+y*y;
} int main()
{
int n,i,b,c,d;
char s[]; scanf("%d %d", &n,&d);
d=d*d;///因为距离只做判断不做计算,所以直接用平方数判断可以避免小数,更加精确 for(i=;i<=n;i++)
{
scanf("%d %d", &a[i].x,&a[i].y);
a[i].v=;
Father[i]=i;
} while(scanf("%s", s) != EOF)
{
if(s[]=='O')
{
scanf("%d", &b);
if(a[b].v==)
{
a[b].v=;
for(i=;i<=n;i++)
{
if(b!=i&&a[i].v&&Len(a[i],a[b])<=d)
{
int j=Find(i);
int k=Find(b); Father[k]=j;
}
}
} }
else
{
scanf("%d %d", &b,&c);
int j=Find(b);
int k=Find(c);
if(j==k)
printf("SUCCESS\n");
else
printf("FAIL\n");
}
}
return ;
}
POJ - 2336 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 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之间是否能够通信 思路: 基础并查集 每次修复一个点重新 ...
随机推荐
- ubuntu 12.04添加桌面启动器
Ubuntu 12.04版本上,无法通过桌面右键菜单建立应用程序启动器:这里参考一个网上方法进行了建立: ubuntu 12.04中,每个应用程序启动器都对应 /user/share/applicat ...
- CURL访问url显示响应时间
curl -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total} http://www.baidu.com 时间指 ...
- C# 循环语句
本次主要学习了for循环语句. for循环语句的基本格式是: for(初始条件;循环条件;状态改变) { 循环体; } break——中断循环,跳出循环. continue——停止本次循环,进入下次循 ...
- sqlserver 经典入门基础书籍
1.SQLServer2005T-SQL数据库设计 作者:胡百敬等著 ISBN:10位[7121053632]13位[9787121053634] 出版社:电子工业出版社 出版日期:2008-1-1 ...
- APP生产流程图片解说
尽我所能总结下一个app的生产过程,未必完整,也未必是所有的app产生的一个过程,不同公司会有很大的不同,我只是想总结下一般的大众的,做个参考. 需求策划: 设计: 开发: 测试: 发布没什么可画的了 ...
- Centos6.6安装Nginx
1.在安装nginx之前,需要先安装该模块需要依赖包 yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel 2.安 ...
- Oracle字符串操作[转:http://www.cnblogs.com/xd502djj/archive/2010/08/11/1797577.html]
ORACLE 字符串操作 1 字符串连接 SQL> select 'abc' || 'def' from dual; 'ABC'|------abcdef 2 小写SQL>select ...
- Mybatis插件原理和PageHelper结合实战分页插件(七)
今天和大家分享下mybatis的一个分页插件PageHelper,在讲解PageHelper之前我们需要先了解下mybatis的插件原理.PageHelper 的官方网站:https://github ...
- cpanel 定时运行sh/php
php -q /home/用户/public_html/cron.php -------------------php格式 /home/用户/public_html ...
- linux下base命令
查看base那么命令的帮助: root@OpenWrt:/# basename --help BusyBox v1.22.1 (2015-09-15 16:38:30 CST) multi-call ...