A - Wireless Network

简介: POJ-2236 Time Limit: 10000MS Memory Limit: 65536KDescription An earthquake takes place in Southeast Asia.

POJ-2236

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 unexpected aftershock attacked, all computers in the network were all broken. The computers are repaired one by one, and the network gradually began to work again. Because of the hardware restricts, each computer can only directly communicate with the computers that are not farther than d meters from it. But every computer can be regarded as the intermediary of the communication between two other computers, that is to say computer A and computer B can communicate if computer A and computer B can communicate directly or there is a computer C that can communicate with both A and B.

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
The first line contains two integers N and d (1 <= N <= 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
For each Testing operation, print “SUCCESS” if the two computers can communicate, or “FAIL” if not.

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

并查集

//AC:3219MS  712kB
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
struct{
    int x,y;
    int rank;
    int parent;
}node[1005];
int compare(int a,int b,int d){
    if((node[a].x-node[b].x)*(node[a].x-node[b].x)+(node[a].y-node[b].y)*(node[a].y-node[b].y)<=d*d)
        return 1;
    else
        return 0;
}
int find(int a){
    if(node[a].parent==a)
        return a;
    return find(node[a].parent);
}
void Union(int a,int b){
    a=find(a);
    b=find(b);
    if(node[a].rank>node[b].rank)
        node[b].parent=a;
    else{
        node[a].parent=b;
        if(node[a].rank==node[b].rank)
            node[b].rank++;
    }
}
int main(){
    int N,d;
    scanf("%d%d",&N,&d);
    for(int i=1;i<=N;i++)
        scanf("%d%d",&node[i].x,&node[i].y);
    char D;
    while(scanf("%c",&D)!=EOF){
        if(D=='O'){
            int a;
            scanf("%d",&a);
            node[a].rank=0;
            node[a].parent=a;
            for(int i=1;i<=N;i++){
                if(node[i].parent){
                    if(compare(a, i, d)){
                        Union(a,i);
                    }
                }
            }
        }
        if(D=='S'){
            int a,b;
            scanf("%d%d",&a,&b);
            a=find(a);
            b=find(b);
            if(a==b)
                printf("SUCCESS\n");
            else
                printf("FAIL\n");
        }
    }
    return 0;
}
目录
相关文章
|
存储 缓存 小程序
微信小程序登录流程解析
微信官方文档有小程序的登录流程时序图,本文围绕这张图从0到1做更具体的解析。微信小程序的登录看上去好像很复杂,实际上只是不同的接口调用、字段返回,整个过程有3方在参与:小程序、开发者服务器、微信服务器。
微信小程序登录流程解析
ERROR: No matching distribution found for gradio>=3.23
该博客文章提供了解决使用pip安装gradio版本3.23时出现的"No matching distribution found"错误的步骤,包括从官网下载相应的whl文件并手动安装。
ERROR: No matching distribution found for gradio>=3.23
|
11月前
|
Ubuntu Shell
解决 Ubuntu 用户登录后的 shell 和功能问题
通过本文的详细介绍,您可以掌握解决Ubuntu用户登录后shell和功能问题的方法,从而确保系统的稳定和正常使用。
481 29
|
SQL 安全 Java
JAVA代码审计SAST工具使用与漏洞特征
JAVA代码审计SAST工具使用与漏洞特征
636 2
|
12月前
|
人工智能 内存技术
Gemini 2.0 Flash Thinking:谷歌推出实验性多模态推理模型,在快速生成的同时展示详细的思考过程
谷歌推出的实验性推理模型Gemini 2.0 Flash Thinking,展示了详细的思考过程,能够在多个领域快速解决问题,并提供推理路径。本文将详细介绍该模型的功能、技术原理及使用限制。
629 26
Gemini 2.0 Flash Thinking:谷歌推出实验性多模态推理模型,在快速生成的同时展示详细的思考过程
|
自然语言处理 Linux iOS开发
【推荐】博客创作必备工具✨
为了帮助博主们更高效地创作和发布内容,本文汇总了从 Markdown 编辑器、截图工具、绘图工具到发布工具的写博客必备工具。这些工具涵盖了文本编辑、图片处理、图表绘制、GIF 录制和多平台发布等多个方面。无论你是初学者还是经验丰富的创作者,这些工具都会为你提供全方位的支持,助力你轻松高效地完成博客创作和发布。
514 64
|
前端开发 JavaScript
jsPDF的常规使用
jsPDF的常规使用
360 62
|
人工智能 自动驾驶 安全
“第四次工业革命”-AI革命
“AI变革”被誉为“第四次工业革命”。中国在AI领域持续发力,占亚太地区AI支出的五成,预计2023年市场规模将达到147.5亿美元,约占全球市场的十分之一。IDC预测,中国生成式AI市场年复合增长率将达86.2%。国内企业如百度、阿里、清华等在AI技术研发和应用方面取得显著进展,推动了无人驾驶、送餐机器人、无人快递车等应用场景的发展。尽管AI带来了降本增效,但也引发了就业和社会压力。总体而言,中国在AI领域的投入和发展势头强劲,未来前景广阔。
1008 0
“第四次工业革命”-AI革命
|
安全 数据可视化 物联网
智慧园区解决方案:科技赋能,打造未来管理新典范
智慧园区作为城市发展的重要组成部分,借助5G、云计算、大数据、物联网等前沿技术,实现高效、活力、绿色、安全的四大核心目标。通过全场景数字化感知、统一数据模型构建、智能化管控与数据化运营、综合安防管理等手段,提升园区运营效率和管理水平,促进产业升级和可持续发展。
718 11
excel 图片地址转成图片
excel 图片地址转成图片
360 1