华为OD机试 - 找数字(Java 2024 E卷 100分)

一、题目描述

给一个二维数组nums,对于每一个元素nums[i],找出距离最近的且值相等的元素,输出横纵坐标差值的绝对值之和,如果没有等值元素,则输出-1。

例如

输入数组nums为

0 3 5 4 2
2 5 7 8 3
2 5 4 2 4

  1. 对于 num[0][0]= 0,不存在相等的值;
  2. 对于 num[0][1] = 3,存在一个相等的值,最近的坐标为num[1][4],最小距离为4;
  3. 对于 num[0][2]= 5,存在两个相等的值,最近的坐标为num[1][1],故最小距离为2;
  4. …
  5. 对于num[1][1]= 5,存在两个相等的值,最近的坐标为num[2][1],故最小距离为1;
  6. …

输出

-1 4 2 3 3
1 1 -1 -1 4
1 1 2 3 2

二、输入描述

  1. 输入第一行为二维数组的行
  2. 输入第二行为二维数组的列
  3. 输入的数字以空格隔开

三、输出描述

数组形式返回所有坐标值。

补充说明

  1. 针对数组num[i][j],满足0<i<=100;0<j<=100;
华为OD机试Python - 找数字 小扇和小船今天又玩起来了数字游戏。小船给小扇一个正整数 n(1 ≤ n ≤ 1e9),小扇需要找到一个比 n 大的数字 m,使得 m 和 n 对应的二进制中 1 的个数要相同,如: 4对应二进制100 8对应二进制1000 其中1的个数都为1个 现在求 m 的最小值 阅读详情

相关推荐

【华为OD】C卷真题 100分: 找数字 JavaScript代码实现[思路+代码]

给一个二维数组nums,对于每一个元素num[i],找出距离最近的且值相等的元素,输出横纵坐标差值的绝对值之和,如果没有等值元素,则输出-1。对于 num[0][2] = 5,存在两个相等的值,最近的坐标为num[1][1],故最小距离为2。对于 num[1][1] = 5,存在两个相等的值,最近的坐标为num[2][1],故最小距离为1。对于 num[0][1] = 3,存在一个相等的值,最近的坐标为num[1][4],最小距离为4。对于 num[0][0] = 0,不存在相等的值。

十年以上编程经验的干货分享 660

2025华为OD机试最新题库-(2025A卷+E卷+D卷)-(JAVA、Python、C++)

2024年8月-2025年2月,OD统一考试考的都是(E卷),题库已为大家准备好,命中率95%以上。

goldarmour的博客 9233

华为od机试|华为od机试真题2025|华为od题库|华为od机考|2025C卷B卷

华为od机试|华为od机试真题2025|华为od题库|华为od机考|华为od机试|华为od机试真题2025|华为od题库|华为od机考|华为od机试|华为od机试真题2025|华为od题库|华为od机考|华为od机试|华为od机试真题2025|华为od题库|华为od机考|B卷C卷

u014481728的博客 10万+

2024华为OD机试(E卷+D卷+C卷)最新题库(Java & Python & C++)

2024华为OD机试(C卷+D卷)最新题库(Java & Python & C++) 关于华为OD ​ 华为的员工补充途径有三种,分别是校招、OD转正和社招。校招是华为唯一的正式员工入职途径,但是从近几届开始竞争非常激烈,尤其是在CV、AI、NLP等赛道上,所以对于C9等专业的学生来说,可以考虑转向一些冷门方向。 ​ OD转正是指在华为工作满一年之后,可以根据部门OD比例、是否来自目标院校、个人工作表现等因素来决定是否能转为正式员工。社招是指通过华为特定的招聘窗口进行投递,但审批流程相对较

学习,你不是一个人在战斗 ~ 961302305(QQ,微信) 5280

华为OD机试 - 幸运数字(Java 2024 E卷 100分)

华为OD机试 2024E卷题库疯狂收录中,刷题。

学Java,找哪吒 3774

华为OD机试|华为od题库|华为od机考|2025真题目录Java实现|2025C卷B卷

华为OD机试|华为od题库|华为od机考|2025真题目录Java实现|B卷C卷|华为OD机试|华为od题库|华为od机考|2025真题目录Java实现|B卷C卷|华为OD机试|华为od题库|华为od机考|2025真题目录Java实现|B卷C卷|华为OD机试|华为od题库|华为od机考|2025真题目录Java实现|B卷C卷|华为OD机试|华为od题库|华为od机考|2025真题目录Java实现|B卷C卷

u014481728的博客 7万+

华为OD机试 - 密室逃生游戏(Java 2024 E卷 100分)

刷的越多,抽中的概率越大,私信哪吒,备注华为OD,加入华为OD刷题交流群,每一题都有详细的答题思路、详细的代码注释、发现新题目,随时更新,全天优快云在线答疑。

学Java,找哪吒 1434

华为OD机试 - 找等值元素(Java 2024 E卷 100分)

华为OD机试 2024E卷题库疯狂收录中,刷题。

学Java,找哪吒 931

模拟电子课设-半导体直流稳压电源的设计和测试

1、学习直流稳压电源的设计方法; 2、研究直流稳压电源的设计方案; 3、掌握直流稳压电路的调试及主要指标的测试方法。二、设计要求和技术指标 1、设计要求1)、设计一个能输出5V-12V连续可调的直流稳压电源,或±12V的直流稳压电源; 2)、根据设计要求和技术指标设计好电路,选好元件及参数,要求绘出原理图,并用Protel 99SE/DXP画出印制板图; 3)、在万能板或面包板上制作一台直流稳压电源; 4)、测量直流稳压电源的稳压系数; 5)、测量直流稳压电源的内阻; 6)、拟定测试方案和设计步

GJZGRB的博客 1970

基于C#的软PLC梯形图编辑器开发实战

本文详细介绍了基于C#开发软PLC梯形图编辑器的实战过程。文章从核心数据结构设计入手,阐述了如何利用C#的面向对象特性构建梯形图元素模型,并实现了图形编辑、指令表输入、逻辑连接拓扑重建等关键功能。重点剖析了模拟PLC执行引擎的扫描周期与能流传递算法,让梯形图逻辑在PC上“活”起来。最后探讨了定时器指令实现、性能优化及项目集成等进阶内容,为工业自动化软件集成提供了灵活高效的解决方案。

weixin_28314575的博客 404

UE4免费资产库新玩法:Quixel Bridge插件安装与Megascans资源导入全攻略

本文详细介绍了如何在UE4中安装Quixel Bridge插件并导入Megascans资源,帮助开发者快速获取高质量3D资产。通过分步教程和实用技巧,提升游戏或影视场景的制作效率,特别适合需要真实感环境的项目。

weixin_27729671的博客 364

高分三号SAR影像超精细条带数据预处理实战:从原始数据到地理编码的完整操作指南

本文提供了高分三号SAR影像超精细条带数据预处理的完整实战指南。详细介绍了从原始数据导入、多视处理、滤波去噪、DEM准备到地理编码与辐射定标的完整流程,帮助用户利用SARscape软件将原始SAR数据转化为可用于分析的地理编码产品。

tree8的博客 576

手把手教你排查Abaqus中的Johnson-Cook损伤参数:避免因d3正负号导致的仿真失败

本文详细解析了Abaqus中Johnson-Cook损伤参数d3正负号设置的关键问题,帮助用户避免因参数错误导致的仿真失败和Excessive distortion报错。通过对比不同文献定义、提供实操指南和典型错误排查流程,有效提升非线性分析的准确性和效率。

weixin_33960567的博客 353

2026华为OD机试 新系统真题题库目录|机考题库 + 算法考点详解

华为OD机试 新系统真题题库目录|机考题库 + 算法考点详解华为od机试,华为od机试真题,华为od机试E卷,华为odE卷,华为od机试真题E卷,华为OD,华为OD机试,华为OD机试真题,华为od机考,华为od机试D卷,华为od机试真题D卷,华为od手撕代码,华为od,华为od机试C卷,华为od e卷,华为2026e卷,od机试,2026E卷,华为OD机试E卷,什么是华为od,华为od介绍,全面了解华为od,2026华为od,如何备战华为od,华为od算法,华为od手撕代码,华为OD机试2024年最新题库,

KJ.JK 4684

使用 Visual Studio Code 连接 ABAP On-Premise 系统做开发的详细配置步骤

本文详细介绍了如何在Visual Studio Code中通过ABAP Development Tools扩展连接ABAP On-Premise系统。关键步骤包括:通过Ctrl+Shift+P打开命令行面板选择「ABAP: New Destination...」创建RFC连接(仅支持SSO单点登录),选择本地SAPGUI中已有的系统,输入Client ID、语言和用户名(无需密码),最后将目标系统添加到工作区即可开始开发。文章强调了企业安全考虑下仅支持SSO的设计理念,并展示了连接配置的JSON格式示例。整

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 984

【STM32Cube_14】使用硬件I2C读写环境光强度传感器(BH1750)

本篇详细的记录了如何使用STM32CubeMX配置STM32L431RCT6的硬件I2C外设读取环境光强度传感器数据(BH1750)

Mculover666的博客(嵌入式) 7239

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

上一篇: 华为OD机试 - 最小的调整次数(Java 双机位A卷 200分)
下一篇: 华为OD机试 - 整理扑克牌(Java 2025 B卷 100分)
哪 吒
哪 吒 2022年度博客之星TOP 1 2022年度博客之星TOP 1 领域专家: 后端开发技术领域 领域专家: 后端开发技术领域
博客等级 码龄9年 59万+粉丝 2933原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

哪 吒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值