Wireless Network POJ 2236

http://poj.org/problem?id=2236

题意:现有一些电脑(编号从 1 - N),在修理好某台电脑并且当这台电脑与其他电脑距离不超过 D 的情况下, 其他电脑可以由这台电脑控制。

      有两种操作:一是修理编号为 x 的某台电脑, 而是询问你编号从 p - q 的电脑是否都彼此联通

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <cstring>
using namespace std;

#define maxn 1500
#define INF 0x3f3f3f3f
int  a[maxn], b[maxn], father[maxn], v[maxn];
int n, d;

int Find(int x)
{
    while(x != father[x])
    {
        x = father[x];
    }

    return x;
}

int ok(int i, int j)
{
    int s = (a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]);
    if( s <= d)
        return 1;

    return 0;
}

int main()
{
    scanf("%d %d", &n, &d);
    d *= d;

    for(int i=1; i<=n; i++)
        scanf("%d %d", &a[i], &b[i]);

    for(int i=1; i<=n; i++)
        father[i] = i;

    char op[5];
    int x, y;
    memset(v, 0, sizeof(v));

    while(scanf("%s", op) != EOF)
    {
        if(op[0]==‘S‘)
        {
            scanf("%d %d", &x, &y);

            if(Find(x) == Find(y))
                printf("SUCCESS\n");
            else
                printf("FAIL\n");

            continue;
        }

        scanf("%d", &x);

        if(!v[x])
        {
            v[x] = 1;

            for(int i=1; i<=n; i++)
            {
                if(v[i] && x != i && ok(i, x))
                {
                    int p = Find(i);
                    int q = Find(x);
                    if(p!=q) father[q]= p;
                }
            }
        }

    }

    return 0;
}

时间: 2024-10-10 04:29:00

Wireless Network POJ 2236的相关文章

Wireless Network (poj 2236 并查集)

Language: Default Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 17602   Accepted: 7418 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network wit

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

链接: http://poj.org/problem?id=2236 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/A 代码: #include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<algorithm> #include<iostream>

A - Wireless Network POJ - 2236

题目大意:有n台坏掉的电脑,给出每台电脑的坐标,然后每次询问输入0(字符) x,表示电脑x恢复正常,输入S x y 询问x和y是否可以联网.只要是x和y的距离小于距离d,那么就可以联网,如果有个中介c使得x到c的距离小于d,y到c的距离小于d,那么x和y也可以联网. 题解:当修复好一台电脑后,然后判断与之前修好的电脑的距离,小于d的话,用并查集连在一起.(没敢这样想,感觉这样会T....) #include<cstdio> #include<iostream> #include&l

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

A - Wireless Network POJ - 2236 Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 50348   Accepted: 20619 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with

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

POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y均能C通信,则x和y可以通信.现在给出若干个操作, O p 代表修复编号为p的电脑 S p q代表询问p和q是不是能通信. 思路: 并查集即可.. 如果修复了一台电脑,则把与它相连距离不超过d的且修复了的放在一个集合里面. #include<cstdio> #include<cstring&

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

Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 6778 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computer

[并查集] POJ 2236 Wireless Network

Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 25022   Accepted: 10399 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap compute

POJ 2236 Wireless Network (并查集)

Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 18066   Accepted: 7618 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computer

POJ 2236 Wireless Network

Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 18146   Accepted: 7660 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpec