华为OD机试 - 恢复数字序列(Java)

题目描述
对于一个连续正整数组成的序列,可以将其拼接成一个字符串,再将字符串里的部分字符打乱顺序。如序列8 9 10 11 12,拼接成的字符串为89101112,打乱一部分字符后得到90811211,原来的正整数10就被拆成了0和1。

现给定一个按如上规则得到的打乱字符的字符串,请将其还原成连续正整数序列,并输出序列中最小的数字。

输入描述
输入一行,为打乱字符的字符串和正整数序列的长度,两者间用空格分隔,字符串长度不超过200,正整数不超过1000,保证输入可以还原成唯一序列。

输出描述
输出一个数字,为序列中最小的数字。

用例

输入 19801211 5
输出 8
说明 无

题目解析


        
【200分】【恢复数字序列】 代码的主要思路是尝试构建连续正整数序列,从长度为 2 到 1000 - k + 2 的滑窗开始,比较滑窗中的字符数量与打乱字符的字符串中字符数量是否一致,以找到满足条件的最小整数序列。每次尝试时,更新滑窗中的字符数量,移除上一个数字并添加新的数字,然后比较滑窗中的字符数量与打乱字符的字符串中字符数量是否一致。通过比较滑窗中的字符数量与打乱字符的字符串中字符数量,逐步构建连续正整数序列,找到满足条件的最小数字,即可解决这个问题。如果找到一个满足条件的滑窗,返回滑窗的起始数字,即为连续正整数序列的最小数字。 阅读详情

相关推荐

华为OD机试 - 恢复数字序列(Python)

我们只需要统计“打乱字符的字符串”中各字符的数量,以及滑窗中各字符的数量,如果所有字符对于的数量都相同,那么说明对应滑窗就是一个符合要求的连续正整数数列,我们只需要取滑窗第一个数值即可。滑窗在运动过程中,可以利用差异比较,即当前滑窗相交于上一个滑窗,失去了一个数字,新增了一个数字,当前滑窗只需要针对失去数字和新增数字的字符做数量修改即可。输入一行,为打乱字符的字符串和正整数序列的长度,两者间用空格分隔,字符串长度不超过200,正整数不超过1000,保证输入可以还原成唯一序列。

m0_46181452的博客 864

华为OD机试Java - 恢复数字序列

对于一个连续正整数组成的序列,可以将其拼接成一个字符串,再将字符串里的部分字符打乱顺序。如序列8 9 10 11 12,拼接成的字符串为89101112,打乱一部分字符后得到90811211,原来的正整数10就被拆成了0和1。现给定一个按如上规则得到的打乱字符的字符串,请将其还原成连续正整数序列,并输出序列中最小的数字。

steven_my的博客 180

华为OD机试 Java -恢复数字序列

对于一个连续正整数组成的序列,可以将其拼接成一个字符串,再将字符串里的部分字符打乱顺序。如序列8 9 10 11 12,拼接成的字符串为89101112,打乱一部分字符后得到90811211,原来的正整数10就被拆成了0和1。现给定一个按如上规则得到的打乱字符的字符串,请将其还原成连续正整数序列,并输出序列中最小的数字。

2302_77831730的博客 78

华为OD机试详细解析:恢复数字序列 - 基于C++、Java、Python、JavaScript四种语言的解题思路与实现

对于一个连续的正整数组成的序列,我们可以将其拼接成一个字符串,再将字符串中的部分字符打乱顺序。现给定一个按如上规则得到的打乱字符的字符串,要求从中恢复出连续的正整数序列,并输出序列中的最小数字。

m0_57781768的博客 220

【华为OD统一考试(B卷)】恢复数字序列,JAVA 题解 | 华为OD机试考题

对于一个连续正整数组成的序列,可以将其拼接成一个字符串,再将字符串里的部分字符打乱顺序。输入一行,为打乱字符的字符串和正整数序列的长度,两者间用空格分隔,字符串长度不超过 200,正整数不超过 1000,保证输入可以还原成唯一序列。现给定一个按如上规则得到的打乱了字符的字符串,请将其还原成连续正整数序列,并输出序列中最小的数字。参加华为 od 机试,一定要注意不要完全背诵代码,需要理解之后模仿写出,通过率才会高。参加华为 od 机试,一定要注意不要完全背诵代码,需要理解之后模仿写出,通过率才会高。

梦想橡皮擦,专栏100例写作模式先行者,现象级专栏 《Python 爬虫 100 例》作者、《滚雪球学 Python 专栏》原创者 1万+

【华为OD机试真题 Java语言】328、恢复数字序列 | 机试真题+思路参考+代码解析

>对于一个连续正整数组成的序例,可以将其拼接成一个字符串,再将字符串里的部分字符打乱顺序。如序例8 9 10 11 12,拼接成的字符 串为89101112,打乱一部分字符后得到90811211,原来的正整数10就被拆成了0和1   现给定一个按如上规则得到的打乱字符的字符串,请将其还原成连续正整数序列,并输出序列中最小的数字

KJ.JK 1955

华为OD机试双机位A卷 - 恢复数字序列 (C++ & Python & JAVA & JS & GO)

华为OD机试2025双机位A卷 恢复数字序列,提供Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解。

qq_45776114的博客 1156

【华为OD机试真题 2025B卷】764、恢复数字序列 | 机试真题+思路参考+代码解析(C++、Java、Py、C语言、JS)

【华为OD机试真题 2025B卷】764、恢复数字序列 | 机试真题+思路参考+代码解析(C++、Java、Py、C语言、JS) 华为od机试,华为od机试真题,华为od机试E卷,华为odE卷,华为od机试真题E卷,华为OD,华为OD机试,华为OD机试真题,华为od机考,华为od机试D卷,华为od机试真题D卷,华为od手撕代码,华为od,华为od机试C卷,华为od e卷,华为2025e卷,od机试,2025E卷,华为OD机试E卷,什么是华为od,华为od介绍,全面了解华为od,2025华为od,如何备战华为

KJ.JK 730

【华为OD机试真题 Java】恢复数字序列

对于一个连续正整数组成的序列,可以将其拼接成一个字符串,再将字符串里的部分字符打乱顺序。如序列8 9 10 11 12,拼接成的字符串为89101112,打乱一部分字符后得到90811211,原来的正整数10就被拆成了0和1。现给定一个按如上规则得到的打乱字符的字符串,请将其还原成连续正整数序列,并输出序列中最小的数字。

A_D_I_D_A_S的博客 113

2023华为od机试真题【恢复数字序列】Java

组成的序列,可以将其拼接成一个字符串,再将字符串里的部分字符打乱顺序。如序列8 9 10 11 12,拼接成的字符串为89101112,打乱一部分字符后得到90811211,原来的正整数10就被拆成了0和1。现给定一个按如上规则得到的打乱字符的字符串,请将其还原成连续正整数序列,并输出序列中最小的数字.1:很多反馈读不懂题目的,主要看示例1就行了,这5个数字,总共8个字符,任意打乱后组成了19801211,题目说了总共5个数字,要你还原原来的5个数字,然后给出这5个数字种的最小值。

斌擎科技 210

unity转微信小游戏:UI大小设置

unity转微信小游戏:UI大小设置

会潜水的小火龙的博客 3270

C++ 程序稳定运行一段时间后异常中止?vc6 运行库的bug!!!

事件查看器提示:错误应用程序 xxxxxxx.exe,版本 0.0.0.0,错误模块 MSVCRTD.DLL,版本 6.0.9782.0,错误地址 0x00012b40。这是一个通信方面的软件,需要长期运行,在压力测试时,高负荷连续运行一定天数时必定崩溃,而且都是在msvcrtd.dll中崩溃。后来在dump文件中发现调用栈在是MSVCRTD.DLL模块,跟踪代码发现是在void * __cdecl _heap_alloc_dbg(        size_t nSize,        int nBloc

qingflying的专栏 2679

Visual Studio 2015 插件开发 从入门到放弃(一)

必需知识:C#和Visual Studio (1)安装 Visual Studio 2015 的时候选择 Visual Studio 扩展性工具(Visual Studio Extensibility Tools)。对于已经安装好 Visual Studio 2015 的小伙伴,可以找VS2015的安装包,或者在程序与功能中找VS2015双击,在VS2015界面中选择 修改,再选择

AncientPeople的博客 2万+

100多台物理GPU服务器,每台服务器上有8张GPU卡,组网

计算网用 IB/RoCEv2 保证低延迟高带宽,支撑 800+GPU 的分布式训练;管理网和存储网独立部署,避免干扰核心通信;全链路冗余和规范布线,确保集群稳定运行;搭配 Slurm/K8s 和监控工具,实现高效管理。该方案可支撑千亿参数大模型训练,且具备极强的扩展性,未来可平滑扩容至 200 + 台服务器。

weixin_42795092的博客 2020

AMD Ross FPGA Agent 实战:用 AI 驱动 Vivado 开发流程

在 EDA 领域,FPGA 开发长期面临工具链重、反馈周期长、报错晦涩等痛点。AI Agent 通过自然语言交互与工具调用,将 Vivado 的 Tcl 批处理流程封装为可编排、可观测的智能体,显著降低查文档与读报告的时间成本。其核心在于 Harness 与 Agent 的协同:Harness 提供安全执行环境,Agent 负责决策与迭代。典型应用包括工程创建、约束生成、综合实现报告解读及比特流失败排查。本文以 AMD Ross 为例,拆解其架构设计与实操方法,帮助开发者理解如何将 Agent 落地到高门槛

weixin_29189363的博客 1021

使用pyqt5实现可勾选的测试用例界面

使用pyqt5实现可勾选的测试用例界面

天赐好车的博客 629

【异常】OpenClaw 连接异常This site can‘t be reached 127.0.0.1 refused to connect Try: Checking the proxy

在访问OpenClaw相关服务时,浏览器提示如下异常信息,无法正常加载页面:Try:补充说明:该报错仅出现于本地访问场景(127.0.0.1为本地回环地址),涉及OpenClaw核心服务的本地连接交互,无外部网络及敏感信息泄露风险。

奶爸的编程之路,也就一周冷个三天 1483

课题申报书成功率提升85%!借助大模型AI精准选题、搭综述框架及提炼创新点(附实操AI提示词)

写一份高质量的课题申报书往往面临许多困难,对很多同仁来说,难就难在:选题既要新又要能落地,文献综述要结构清晰还得有观点,研究目标要写得有逻辑还不能夸大,创新点必须得新。而且就算你有思路,也卡在怎么组织语言,怎么压缩字数上。现在我们用ChatGPT等AI工具,可以帮我们从“选题策划 → 综述撰写 → 目标拆解 → 创新提炼 → 团队结构”实现申报工作的全流程,我们要做的就是设计好提示词和收集相关资料。这篇文章将会从申报工作的六个核心模块出发,并给出参考AI提示词,帮你快速提升课题申报效率。

智能AI让学术科研更容易 906

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

深度学习工具包 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")

上一篇: 华为OD机试 - 最少交换次数(Java)
下一篇: 华为OD机试 - 代表团坐车(Java)
清水乐园
博客等级 码龄13年 175粉丝 398原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

打赏作者

清水乐园

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

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

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

打赏作者

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

抵扣说明:

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

余额充值