首页 > 其他分享 >Wireless Network

Wireless Network

时间:2024-05-14 12:40:50浏览次数:12  
标签:pre Network int computers communicate two Wireless computer

描述

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.

输入

There are multiple test cases. 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. "R 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.

  3. "Q", which means quiting all the testing operations of each test case.

The input will not exceed 300000 lines.

输出

For each Testing operation, print "SUCCESS" if the two computers can communicate, or "FAIL" if not.

样例输入

4 1
0 1
0 2
0 3
0 4
R 1
R 2
R 4
S 1 4
R 3
S 1 4
Q

样例输出

FAIL
SUCCESS

提示

POJ 2236

思路

  • 对于R p操作,将指定编号的电脑p标记为已修复,并检查它与网络中其他已修复电脑的距离,如果距离在d以内,则将它们合并。

  • 对于S p q操作,检查电脑pq是否能够通信(即它们是否有相同的根节点),并输出相应的结果。

code

#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
typedef long long ll;
#define D(x1,x2) (x1-x2)*(x1-x2)
int pre[maxn];
struct Station {
	ll x, y;
	int work;//1代表已维修好,可以工作
}station[maxn];

void init() {
	for (int i = 1; i < maxn; i++) {
		pre[i] = i;
	}
}
int find(int x) {
	return pre[x] == x ? x : pre[x] = find(pre[x]);
}
void merge(int x, int y) {
	int rootx = find(x);
	int rooty = find(y);
	if (rootx != rooty) {
		pre[rootx] = rooty;
	}

}

int main()
{
	ll n, d;
	while (scanf("%lld%lld",&n,&d)!=EOF) {//n为电脑数,d为通信最小距离
		for (int i = 1; i <= n; i++) {
			scanf("%d%d",&station[i].x,&station[i].y);
			station[i].work = 0;
		}
		char cz[2];
		init();
		while (scanf("%s", cz) != EOF) {
			if(cz[0] == 'Q') break;
			if (cz[0] == 'R') {//维修
				int p;
				scanf("%d", &p);
				station[p].work = 1;
				for (int i = 1; i <= n; i++) {
				ll deltx = D(station[i].x , station[p].x);
				ll delty = D(station[i].y , station[p].y);
					if (i!=p && station[i].work == 1 && (deltx + delty <= d * d)) {
						merge(p, i);
					}
				}
			}
			else {
				int p, q;
				scanf("%d%d", &p,&q);
					if (find(p) == find(q) ) {
						printf("SUCCESS\n");
					}
					else {
						printf("FAIL\n");
					}
			}
		}
	}
	return 0;
}

标签:pre,Network,int,computers,communicate,two,Wireless,computer
From: https://www.cnblogs.com/6Luffy6/p/18191082

相关文章

  • KAN: Kolmogorov–Arnold Networks 学术论文全译
    KAN:Kolmogorov–ArnoldNetworks学术论文全译来源 https://zhuanlan.zhihu.com/p/696001648 KAN:Kolmogorov–ArnoldNetworks https://arxiv.org/pdf/2404.19756讨论Applicationaspects:WehavepresentedsomepreliminaryevidencesthatKANsaremoreeffective......
  • 网络策略_NetworkPolicy
    网络策略NetworkPolicy前端通过访问后端的API接口来获取数据库中的数据前端、API接口、数据库在k8s中都为podk8s要求所有pod可以互相访问,但生产中,不能让前端直接访问后端数据库目标是保护数据库,使其不允许从除了API以外的任何pod访问apiVersion:networking.k8s.io/v1kind:......
  • Outrageously Large Neural Networks The Sparsely-Gated Mixture-of-Experts Layer
    目录概MoE训练ShazeerN.,MirhoseiniA.,MaziarzK.,DavisA.,LeQ.,HintonG.andDeanJ.Outrageouslylargeneuralnetworks:Thesparsely-gatedmixture-of-expertslayer.ICLR,2017.概Mixture-of-Experts(MoE).MoE通过一gatingnetwork选择不同的exp......
  • 第一章:Introduction to Interconnection Networks
    第一章:互联网络介绍数字系统三个基本组件逻辑(logic)存储(memory)通信(communication)随着技术进步,当前大部分数字芯片系统的瓶颈在于通信,组件之间的通信偏绿远远落后于处理器时钟频率,因此互联是未来数字系统成功的关键因素。关于互联网络的三个问题什么是互联网络互连网络是......
  • nmcli NetworkManager 的命令行工具 它允许用户管理网络连接和网络设备
    1、列出所有连接nmcliconnectionshow2、启用/禁用网络连接nmcliconnectionup<ConnectionName>nmcliconnectiondown<ConnectionName>3、连接到一个Wi-Fi网络nmclidevicewificonnect<SSID>password<password>4、显示网络设备的状态nmclidevicestatus......
  • 全网最全的nginx服务器部署-命令行_network
    选用的服务器我选用的阿文云服务器,地址是香港,优点是价格十分便宜登录|阿文云计算(xn--kcr903c616a.cn)ssh登录服务器我用的是ubuntu的里面的ssh去登录,用的虚拟机ssh-lroot[你的服务器地址]ssh-lroot38.55.232.150命令的配置安装依赖yuminstall-ygcc......
  • Simple Neural Network
    神经网络——从PLA到BP神经网络0.推荐阅读B站白板推导系列二十三(没有任何数学推导,能够看得很舒服)李沐-动手学深度学习1.感知机学习算法(PerceptronLearningAlgorithm)相信能看到神经网络的朋友对于机器学习的基础算法已经了解了个大概了,如果你没有听说过感知机算法,......
  • 论文解读(MAML)《Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks
    Note:[wechat:Y466551|可加勿骚扰,付费咨询]论文信息论文标题:Model-AgnosticMeta-LearningforFastAdaptationofDeepNetworks论文作者:ChelseaFinn、PieterAbbeel、SergeyLevine论文来源:2017 论文地址:download 论文代码:download视屏讲解:click1-摘要我们提出......
  • centos7出现网络不可达connect network is unreachable?
    centos7出现网络不可达connect:networkisunreachable?问题:在Linux系统中,用户尝试修改IP地址配置后,遇到ping命令提示connect:networkisunreachable,表明网络不可达。原因分析:IP配置错误:修改后的IP地址可能不在正确的子网内,或者与默认网关不在同一网段,导致无法正常通信......
  • 【Network Automation系列】-- 第一章
    引言:本系列是根据《MasteringPythonNetworkingThirdEdition》翻译整理出来的,原著作者:EricChou,大家可以关注一下。随着网络工程领域的快速变化,我们无疑也经历了类似的变化。随着软件开发越来越多地集成到网络的各个方面、传统的命令行接口和垂直集成中,网络堆栈方法不再是管......