无线电网络

  题目大意:就是地震后,所有的电脑都坏了,现在可以修复,而且要重新连成一个网络,两台电脑之间最大连接距离为D,两台电脑可以有中继电脑,按O修复电脑,按S测试两台电脑是否有链接,如果有就输出SUCCESS,不行就FAIL

  一看到电脑,我就联想到了查并集,这一题也不例外,我们维护在距离内的查并集就可以了,具体思路不难,每一次修复都扫描所有的节点看能否连接即可

  

 #include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#define MAX 1004 using namespace std;
typedef int Position;
typedef struct _set
{
int x;
int y;
}Point; static Point Comp[MAX];
static Position Set[MAX];
static bool used[MAX];
static int max_dist; Position Find(Position);
void Unite_Set(Position, Position);
void Repaired(const int, Position);
void Test(Position, Position);
double Dist_Cal(Position, Position); int main(void)
{
int n, tmp_p, tmp_x, tmp_y;
char choice;
while (~scanf("%d%d", &n, &max_dist))
{
memset(Set, -, sizeof(Set));
memset(used, , sizeof(used));
for (int i = ; i <= n; i++)
scanf("%d%d", &Comp[i].x, &Comp[i].y);
getchar();
while (~scanf("%c", &choice))
{
if (choice == 'O')
{
scanf("%d", &tmp_p);
Repaired(n, tmp_p);
}
else
{
scanf("%d%d", &tmp_x, &tmp_y);
Test(tmp_x, tmp_y);
}
getchar();
}
}
return ;
} double Dist_Cal(Position i, Position j)
{
return sqrt((double)((Comp[i].x - Comp[j].x)*(Comp[i].x - Comp[j].x)) +
(double)((Comp[i].y - Comp[j].y)*(Comp[i].y - Comp[j].y)));
} void Unite_Set(Position x, Position y)
{
Position px, py;
px = Find(x); py = Find(y);
if (px != py)
{
if (Set[px] < Set[py])//按大小求并
{
Set[px] += Set[py];
Set[py] = px;
}
else
{
Set[py] += Set[px];
Set[px] = py;
}
}
} Position Find(Position x)
{
if (Set[x] < )
return x;
else return Set[x] = Find(Set[x]);
} void Repaired(const int n, Position x)
{
used[x] = ;
for (int i = ; i <= n; i++)
{
if (i == x || !used[i]) continue;
if (Dist_Cal(x, i) <= (double)max_dist)
Unite_Set(x, i);
}
} void Test(Position x, Position y)
{
Position px, py;
px = Find(x);
py = Find(y); if (px == py) puts("SUCCESS");
else puts("FAIL");
}

                    

DisJSet:Wireless Network(POJ 2236)的更多相关文章

  1. Wireless Network(POJ 2236)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 20724   Accepted: 871 ...

  2. Day5 - B - Wireless Network POJ - 2236

    An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...

  3. (并查集) Wireless Network --POJ --2236

    链接: http://poj.org/problem?id=2236 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...

  4. Wireless Network POJ - 2236 (并查集)

    #include<iostream> #include<vector> #include<string> #include<cmath> #includ ...

  5. A - Wireless Network POJ - 2236

    题目大意:有n台坏掉的电脑,给出每台电脑的坐标,然后每次询问输入0(字符) x,表示电脑x恢复正常,输入S x y 询问x和y是否可以联网.只要是x和y的距离小于距离d,那么就可以联网,如果有个中介c ...

  6. A - Wireless Network POJ - 2236-kuangbin带你飞

    A - Wireless Network POJ - 2236 Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 50348 ...

  7. POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集

    POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...

  8. [并查集] POJ 2236 Wireless Network

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 25022   Accepted: 103 ...

  9. poj 2236:Wireless Network(并查集,提高题)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 677 ...

随机推荐

  1. collections_python

    代码 import collections#counter继承字典的方法,items(),keys(),vavle() obj = collections.Counter('acbdafcbad') ...

  2. BZOJ1968 [Ahoi2005]COMMON 约数研究

    Description Input 只有一行一个整数 N(0 < N < 1000000). Output 只有一行输出,为整数M,即f(1)到f(N)的累加和. Sample Input ...

  3. 安装最新版本的ReSharper导致原生全局搜索工具的消失问题

    经过检测,是由于启用了一个插件导致的,禁用即可,如下图:

  4. 抓包利器Fiddler

    1).Fiddler安装 a.下载地址: http://fiddler2.com/get-fiddler b.安装:省略(下一步...下一步即可) 2).Fiddler配置 a.允许远程计算机连接Fi ...

  5. Linux中的TUN/TAP设备

    今天才发现这家伙...怎么讲...深以为耻.晚上的任务是加深对它的了解,就这么定了. 1. General questions.1.1 What is the TUN ?  The TUN is Vi ...

  6. newinstance和new有什么区别

    用newInstance与用new是区别的,区别在于创建对象的方式不一样,前者是使用类加载机制,那么为什么会有两种创建对象方式?这个就要从可伸缩.可扩展,可重用等软件思想上解释了.Java中工厂模式经 ...

  7. linux内存回收 内核参数

    ss -atu| awk '/^tcp/{++S[$2]} END {for(a in S) print a,S[a]}' ps up pid (RSS:实际内存大小,长驻内存) ps o pid,c ...

  8. ci默认控制器

    默认控制器 前面提到,如果在请求中没有指明具体的控制器,CI将会把页面重定向到一个系统默认的页面.这个默认页面可以自己设定,它存放在如下地址:/system/application/config/ro ...

  9. 不要在初始化方法和dealloc方法中使用Accessor Methods

    苹果在<Advanced Memory Management Programming Guide>指出: Don’t Use Accessor Methods in Initializer ...

  10. js中window的属性

    Window的属性 属性描述 closed 获取引用窗口是否已关闭. defaultStatus 设置或获取要在窗口底部的状态栏上显示的缺省信息. dialogArguments 设置或获取传递给模式 ...