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 小希的迷宫 基 ...
随机推荐
- Eclipse 打包Web项目
使用插件fatjar Fat jar插件 http://kurucz-grafika.de/fatjar eclipse菜单栏 help->install new software...-> ...
- kaptcha验证码使用
参数配置: Constant 描述 默认值 kaptcha.border 图片边框,合法值:yes , no yes kaptcha.border.color 边框颜色,合法值: r,g,b (and ...
- shell里的/dev/null 2>&1详解
shell中可能经常能看到: >/dev/null 2>&1 命令意思是:标准输出stdout 和标准错误输出stderr 也重定向到空设备文件,即不显示输出信息 分解这个组合:“ ...
- 一个SQL调优/优化(SQL TUNING)“小把戏”“哄得”小朋友挺满意
前几天,去一个用户那里,解决完问题,和一个小朋友闲聊,他有点愁眉不展.郁郁寡欢的样子,似乎没心情和我说话,之前,他的话是最多的,见此状,我就问:怎么了?小朋友?,他说,这几天应用人员说他的某个模块的性 ...
- spring创建单例bean
(使用的spring版本是3.2.10) 在xml文件中配置一个普通的bean,默认使用单例,创建该bean的调用栈如下: ClassPathXmlApplicationContext //Class ...
- Executors类的newFixedThreadPool, newCachedThreadPool, newScheduledThreadPool
Executors 类对 ThreadPoolExecutor 的构造函数进行了封装,使用该类可方便地创建线程池. 1. newFixedThreadPool public static Execut ...
- spring cloud 学习(一)初学SpringCloud
初学SpringCloud 前言 在SpringBoot的坑还没填完的情况下,我又迫不及待地开新坑了.主要是寒假即将结束了,到时又得忙于各种各样的事情……留个坑给自己应该就会惦记着它,再慢慢地补上…… ...
- 如何合理的规划一次jvm性能调优
https://blog.csdn.net/miracle_8/article/details/78347172 摘要: JVM性能调优涉及到方方面面的取舍,往往是牵一发而动全身,需要全盘考虑各方面的 ...
- simulate mdns message
use dns-sd command simulate mdns message: dns-sd -R test _test._tcp local 1234 a=1111111111111111111 ...
- Flash Player离线安装包下载指南
在机房里装软件,没网是正常现象,有些老师要装Firefox/Chrome浏览器要有Flash,网上搜来搜去都是在线安装包一日在V2EX闲逛时发现了一位大神给出了Flash的离线安装包下载方式,在此立个 ...