POJ 2236 Wireless Network

题目链接:

POJ 2236 Wireless Network

并查集:判断俩点之间的连通性,不过是带受限制条件的判断题,主要把握好这个判断就可以了,用一个数组记录该点是否可行,每次接收一个点就对整个数组经行一次扫 描 把在限制条件内的点都并入集合 ,然后判断俩个点是否连通就可以了

/*******************************************
    > File Name: poj_2236.cpp
    > Author: dulun
    > Mail: dulun@xiyoulinux.org
    > Created Time: 2016年03月27日 星期日 12时17分18秒
 ******************************************/

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define LL long long
using namespace std;

const int N = 1086;
int d;
bool use[N];

struct Node 
{
    int pre;
    int x, y;
};
Node node[N];

int flag[N];
int p[N];

void init() { for(int i = 0; i < N; i++) p[i] = i; }
int find(int x) { return x == p[x]? x:p[x] = find(p[x]); }

int main()
{
    int n, d;
    scanf("%d%d", &n, &d);
    init();
    memset(flag, 0, sizeof(flag));
    for(int i = 1; i <= n; i++)
    {
        scanf("%d%d", &node[i].x, &node[i].y);
    }
    char cmd[4];
    while(~scanf("%s", cmd))
    {
        int a, b;
        if('O' == cmd[0])
        { 
            scanf("%d", &a);
            flag[a] = 1;
            for(int j = 1; j <= n; j++)
            {
                int ans = (node[j].x - node[a].x) * (node[j].x - node[a].x);
                ans+=(node[j].y - node[a].y) * (node[j].y - node[a].y);
                if(ans <= d*d && flag[j])
                {
                    int t1 = find(a);
                    int t2 = find(j);
                    if(t1 != t2) p[t1] = t2;
                }
            }
        }
        else
        {
            scanf("%d%d", &a, &b);
            int t1 = find(a);
            int t2 = find(b);
            if(t1 == t2) printf("SUCCESS\n");
            else printf("FAIL\n");
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值