Wireless Network 并查集
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
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
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 遇到这种坐标求距离的最好就是输入double精确度高,然后并查集 代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <string>
#include <cmath>
using namespace std;
int n,d,p,q;
char ch;
int f[];
int stack[],head;
struct loc
{
double x,y;
int id;
}ro[];
void init()
{
for(int i=;i<=n;i++)
f[i]=i;
}
int getf(int x)
{
if(x!=f[x])f[x]=getf(f[x]);
return f[x];
}
int merge(int x,int y)
{
int xx=getf(x),yy=getf(y);
f[yy]=xx;
}
void check(int a,int b)
{
if(sqrt(pow(ro[a].x-ro[b].x,)+pow(ro[a].y-ro[b].y,))<=d)merge(a,b);
}
int main()
{
scanf("%d %d",&n,&d);
init();
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&ro[i].x,&ro[i].y);
} while(cin>>ch)
{
if(ch=='O')
{
scanf("%d",&p);
stack[head++]=p;
for(int i=;i<head-;i++)
{
check(stack[i],p);
}
}
else
{
scanf("%d %d",&p,&q);
if(getf(p)==getf(q))cout<<"SUCCESS"<<endl;
else cout<<"FAIL"<<endl;
}
}
}
Wireless Network 并查集的更多相关文章
- POJ 2236 Wireless Network (并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 18066 Accepted: 761 ...
- POJ2236 Wireless Network 并查集简单应用
Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...
- 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 ...
- POJ2236 Wireless Network 并查集
水题 #include<cstdio> #include<cstring> #include<queue> #include<set> #include ...
- [LA] 3027 - Corporative Network [并查集]
A very big corporation is developing its corporative network. In the beginning each of the N enterpr ...
- LA 3027 Corporative Network 并查集记录点到根的距离
Corporative Network Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [S ...
- UVALive - 3027 Corporative Network (并查集)
这题比较简单,注意路径压缩即可. AC代码 //#define LOCAL #include <stdio.h> #include <algorithm> using name ...
- 【转】并查集&MST题集
转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基 ...
随机推荐
- RabbitMQ入门_12_发布方确认
参考资料:https://www.rabbitmq.com/confirms.html 通过 ack 机制,我们可以确保队列中的消息一定能被消费到.那我们有办法保证消息发布方一定把消息发送到队列了吗? ...
- English trip -- VC(情景课)10 C I like to watch TV. 我爱看电视
Grammar focus 语法点: like to do you do they What does he like to do? does she Practice 练习 ...
- LeetCode--069--x的平方根
问题描述: 实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 示例 1: 输入: 4 输出: ...
- Rspec: everyday-rspec实操。FactoryBot预构件 (rspec-expectations gem 查看匹配器) 1-4章
总文档连接: RSpec.info/documentation/ 包括core, expectiation,rails , mock, 点击最新版本,然后右上角搜索class, method. 第3章 ...
- python-day21--os模块
os模块是与操作系统交互的一个接口''' os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作 ...
- python-day17--生成器
1.本质:就是迭代器 2.生成器函数: def func(): a=1 b=2 yield a #要返回的第一个值 yield b #要返回的第二个值 ret = func() #拿到一个生成器pri ...
- python 爬取京东手机图
初学urllib,高手勿喷... import re import urllib.request #函数:每一页抓取的30张图片 def craw(url,page): imagelist = []# ...
- C#图片转换成二进制流并且保存到sql server数据库
注意:我要存储文件二进制流的列的类型是text,不是image类型. 我已经实现了从数据库中读取text类型的二进制流,,现在就是不知道怎么存进去. 我的部分关键代码: StreamReader sr ...
- spting Boot 创建一个springBoot项目
spting Boot 创建一个springBoot项目 1)学习springBoot使用软件:IDEA软件(前面的文章有安装idea的过程). 也可以使用另一种方法在https://start.sp ...
- OC 类的本质和分类
一.分类 (一)分类的基本知识 概念:Category 分类是OC特有的语言,依赖于类. 分类的作用:在不改变原来的类内容的基础上,为类增加一些方法. 添加一个分类: 文件结构图: 在分类中添加一 ...