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 小希的迷宫 基 ...
随机推荐
- MSSQL 一坑 SQL Management Studio 管理工具的快捷方式被删掉了
如果确定已经安装的情况下,到这里去找下吧(我这里用的是sql 2008) C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Co ...
- Loading Xps from MemoryStream
A common way of loading XpsDocument is to load it from file: XpsDocument document = new XpsDocument( ...
- memcached 内存初始化与key-value存储
本次笔记未涉及到slab的动态重新平衡分配 /**首先介绍一下一个跟内存相关的非常重要的概念,内存块类型数据结构:*/ typedef struct { unsigned int size; /* c ...
- Windows 10 设置 Java 环境变量
首先你需要在我的电脑中打开,找到环境变量属性. 找到环境变量属性 找到环境变量属性后单击将会看到下面的设置界面. 在这个界面中设置高级系统设置. 环境变量 在弹出的界面中选择设置环境变量. 系统变量 ...
- HDU-2829 Lawrence (DP+四边形不等式优化)
题目大意:有n个敌方军火库呈直线排列,每个军火库有一个值vi,并且任意相邻的两个库之间都有通道相连.对于任意一条连起来的军火库链,它对我方的威胁可以用函数w(i,j)表示为:w(i,j)=vi*sum ...
- Android studio jni
首先我们要明确几个概念,jni,ndk,共享库(.so). jni是java native interface的缩写,java 本地接口.它提供了若干的API实现了Java和其他语言的通信(主要是C/ ...
- dp练习(1)——马走日字
3328: 马走日字 时间限制: 1 Sec 内存限制: 128 MB提交: 35 解决: 5[提交][状态][讨论版] 题目描述 一次外出旅游,你路上遇到了一个骑着马的强盗,你很害怕,你需要找一 ...
- Java远程调试 java -Xdebug各参数说明
JAVA自身支持调试功能,并提供了一个简单的调试工具--JDB,类似于功能强大的GDB,JDB也是一个字符界面的 调试环境,并支持设置断点,支持线程线级的调试 JAVA的调试方法如下: 1.首先支持J ...
- MyBatis Generator自动创建代码
MyBatis Generator自动创建代码 1.首先在eclipse上安装mybatis插件 2.创建一个mavenWeb项目. 3.在resource中写入一个xml,一定要与我得同名 < ...
- Oracle12c中性能优化新特性之新增APPROX_COUNT_DISTINCT 快速唯一值计数函数
Oracle11g中,为了改善DBMS_STATS包收集统计信息时的唯一值计数功能,增加了 APPROX_COUNT_DISTINCT函数,但文档中未记载.Oracle12c文档中包括了该函数,因此, ...