华为OD机试 - 金字塔/微商的收入 - 回溯(Python/JS/C/C++ 2025 A卷 100分)

在这里插入图片描述

华为OD机试 2025A卷题库疯狂收录中,刷题点这里

专栏导读

本专栏收录于《华为OD机试真题(Python/JS/C/C++)》。

刷的越多,抽中的概率越大,私信哪吒,备注华为OD,加入华为OD刷题交流群,每一题都有详细的答题思路、详细的代码注释、3个测试用例、为什么这道题采用XX算法、XX算法的适用场景,发现新题目,随时更新。

一、题目描述

一个XX产品行销总公司,只有一个boss,其有若干一级分销,一级分销又有若干二级分销,每个分销只有唯一的上级分销.
规定,每个月,下级分销需要将自己的总收入 (自己的+下级上交的) 每满100元上交15元给自己的上级。

现给出一组分销的关系,和每个分销的收入,请找出boss

boss的收入 已支持(Java & JS & Python & C & C++),考察:递归 || 拓扑排序 阅读详情

相关推荐

华为OD机试 - BOSS的收入(Java)

另外,我们还需要注意,遍历到第二个一维数组时,agent[本级id]可能有了下级上交的收入,因此:本级收入 += agent[本级id],当然前提是agent[本级id]有值。将每行输入转为一个数组,数组包含三个要素:[本级id,上级id,本级收入],这样就会得到一个二维数组。本题的顶级代理商可能不是0,因此我们需要在对二维数组排序后,取得顶级代理商的代号first。遍历二维数组,根据遍历得到的一维数组:[本级id,上级id,本级收入]首先,从用例来看,上下级关系,不是连续,比如2的上级不是1,而是0。

qq_34143141的博客 589

2026华为OD机试(Python)真题【E卷+A卷+B卷+C卷+D卷】目录+在线OJ

华为OD机试真题题库【E卷+A卷+B卷+C卷+D卷】目录,Python实现。

MISAYAONE的博客 28万+

2026华为OD机试(C语言)真题【E卷+A卷+B卷+C卷+D卷】目录+在线OJ

华为OD机试真题题库【E卷+A卷+B卷+C卷+D卷】目录,C语言实现。

MISAYAONE的博客 11万+

2026华为OD机试(JavaScript)真题【E卷+A卷+B卷+C卷+D卷】目录+在线OJ

华为OD机试真题题库【E卷+A卷+B卷+C卷+D卷】目录,JavaScript实现。

MISAYAONE的博客 8万+

2026华为OD机试(C++)真题【E卷+A卷+B卷+C卷+D卷】目录+在线OJ

华为OD机试真题题库【E卷+A卷+B卷+C卷+D卷】目录,C++实现。

MISAYAONE的博客 20万+

2026华为OD机试(JAVA&Go)真题【E卷+A卷+B卷+C卷+D卷】目录+在线OJ

华为OD机试真题题库【E卷+A卷+B卷+C卷+D卷】目录,Java实现。

MISAYAONE的博客 34万+

华为OD机试 新系统 双机位C卷 往年真题 机考题库(持续收录中)以及算法考点详解

每一题都有详细的答题思路、详细的代码注释、样例测试,发现新题目,随时更新,全天优快云在线答疑。

学Java,找哪吒 7万+

华为OD机试E卷 - boss的收入(Java & Python& JS & C++ & C )

一个XX产品行销总公司,只有一个boss,其有若干一级分销,一级分销又有若干二级分销,每个分销只有唯一的上级分销。规定,每个月,下级分销需要将自己的总收入(自己的+下级上交的)每满100元上交15元给自己的上级。现给出一组分销的关系,和每个分销的收入,请找出boss并计算出这个boss的收入。输入:分销关系和收入:[[分销id 上级分销id 收入], [分销id 上级分销id 收入], [分销id 上级分销id 收入]]输出:[boss的ID, 总收入]

算法大师! 4086

华为OD机试 - 金字塔,BOSS的收入(JS)

找到顶级代理商号root后,提供fa_ch,找到root代理商的所有子代理商chs,然后遍历chs,得到每一个ch的赚的钱,从每个ch赚的钱中100抽15,汲取到root代理商赚的钱中。而顶级代理商必然没有父级,因此,我们只要遍历agents,用被遍历到的每一个agent去ch_fa中找,如果找不到,则说明对应的agent就是顶级代理商号root。因此,本题要求顶级代理商的钱,其实就是一个深搜过程,即每个父级代理商的钱 要从其所有子级商汲取(每100元抽15元)。代理商代号 上级代理商代号 代理商赚的钱。

m0_46181452的博客 323

华为od机考 C++【BOSS的收入】

在一个销售团队中,每个销售员在完成销售后都需要支付一部分利润给他们的上级,这种结构类似于金字塔。现在,给定每个销售员的销售额和他们的直接上级,你的任务是计算金字塔顶部的Boss的总收入。销售员2从销售中赚取了323元,并从销售员3那里获得了额外的180元(1203的15%),所以销售员2的总收入是503元。Boss从销售员1、2和3那里总共获得了105元(223的15% + 323的15% + 180的15%)。第一个是Boss的ID(这应该总是0),第二个是Boss的总收入。该销售员的直接上级的ID。

wtswts1232的博客 927

2023华为od机试真题B卷【BOSS的收入】C++ 语言

一个XX 产品行销总公司,只有一个 boss,其有若干一级分销,一级分销又有若干二级分销,每个分销只有唯一的上级分销规定,每个月,下级分销需要将自己的总收入(自己的+下级上交的)每满 100 元上交 15 元给自己的上级.现给出一组分销的关系,和每个分销的收入,请找出 boss 并计算出这 boss 的收入。比如: 收入 100 元上交 15 元,收入 199 元(99 元不够 100)上交 15 元收入 200 元,上交 30 元。

MISAYAONE的博客 922

【OD统一考试(B卷)】Boss的收入,JAVA 解答

分销关系和收入: [[分销id 上级分销的ld 收入,[分销id 上级分销的id 收入],[分销id 级分销的id 收入]]一个 XX 产品行销总公司,只有一个 boss,其有若干一级分销,一级分销又有若干二级分销,每个分销只有唯一的上级分销.规定,每个月,下级分销需要将自己的总收入 (自己的+下级上交的) 每满 100 元上交 15 元给自己的上级.现给出一组分销的关系,和每个分销的收入,请找出 boss 并计算出这个 boss 的收入。给定的输入数据都是合法的,不存在环路,重复的。

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

华为OD机试 - 金字塔,BOSS的收入(Python)

另外,我们还需要注意,遍历到第二个一维数组时,agent[本级id]可能有了下级上交的收入,因此:本级收入 += agent[本级id],当然前提是agent[本级id]有值。将每行输入转为一个数组,数组包含三个要素:[本级id,上级id,本级收入],这样就会得到一个二维数组。本题的顶级代理商可能不是0,因此我们需要在对二维数组排序后,取得顶级代理商的代号first。遍历二维数组,根据遍历得到的一维数组:[本级id,上级id,本级收入]首先,从用例来看,上下级关系,不是连续,比如2的上级不是1,而是0。

m0_46181452的博客 578

华为OD- 金字塔,BOSS的收入-2024年OD(E卷)

微商模式比较典型,下级每赚 100 元就要上交 15 元,给出每个级别的收入,求出金字塔尖上的人收入。代理商代号 上级代理商代号 代理商赚的钱。输出一行,两个以空格分隔的整数,含义如下。金字塔顶代理商 最终的钱数。

蜗牛快快快快跑的博客 718

ZEMAX知识点:坐标间断面(coordinate break)

zemax知识点:坐标间断面

weixin_47638568的博客 1万+

什么!!!寒假就要准备暑期实习

介绍暑期实习,从作用,时间线,投递渠道,技术准备,常见问题,经验教训几个方面介绍暑期实习

今天不coding的博客 1724

如何解决Windows系统中缺失oem*.inf文件导致的软件运行问题

本文详细解析了Windows系统中因oem*.inf文件缺失导致软件无法运行的常见问题。文章阐述了oem*.inf文件作为安装信息文件的重要作用,并提供了从精准定位文件路径、安全获取与替换文件的手动修复步骤,到利用专业工具进行一站式修复的完整解决方案。最后,还给出了从软件安装来源、卸载习惯到系统维护等方面的预防措施,帮助用户彻底避免此类问题。

water的专栏 546

Flutter蓝牙开发实战:flutter_blue_plus核心功能与实现原理剖析

本文深入剖析了Flutter蓝牙开发插件flutter_blue_plus的核心功能与实现原理。文章从源码解析入手,详细讲解了蓝牙状态管理、设备扫描、GATT连接、服务发现以及数据读写等关键流程的实现机制,并分享了实战中的性能调优与常见问题解决方案,帮助开发者高效构建跨平台蓝牙应用。

weixin_29014237的博客 443

VCS的增量和分离编译

vcs的增量和分离编译

yunduor909的博客 3302

【数据中台】数据中台架构搭建百科全书

0、前言 当前,大部分企业不再建设从源数据采集到分析应用的烟囱式系统,更倾向于数据集中采集、存储,并应用分层建设。这种方式一方面有利于应用系统的快速部署,另一方面也保证了数据的集中管理与运营,体现数据的资产、资源属性。 数据中台的出现弥补了数据开发和应用开发之间由于开发速度不匹配而出现的响应力不足等缺陷问题。 数据中台是国内学者提出的概念,起始于阿里的“大中台、小前台”概念。阿里的中台是从管理的角度出发,以中台事业部集中数据搜索,技术及产品,数据共享等多个部门的功能。其他组织或企业建设数据中台不一定需

Sunny的专栏 8405

Python爬虫实战:百度贴吧帖子与评论抓取全攻略(附舆情分析技巧)

基础配置# 要爬取的贴吧名称(替换成自己需要的,比如“XX手游吧”)TIEBA_NAME = "XX手游"# 分页参数(每页50条帖子,可根据需求调整)PAGE_NUM = 3 # 爬取前3页帖子,共150条# 请求头(从浏览器复制自己的,更真实)Win64;

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 2384

LangGraph-StateGraph 和 Graph API 源码分析

摘要: StateGraph是LangGraph的核心API,用于构建有状态工作流图。本文分析了其实现原理,包括: 核心类关系:StateGraph(构建器)和CompiledStateGraph(继承自Pregel的可执行图) 关键流程:状态模式到通道的映射、节点到PregelNode的转换 实现特点: 支持TypedDict和Pydantic两种状态模式 自动选择通道类型(LastValue或BinaryOperatorAggregate) 通过映射函数处理节点输入输出 边实现基于通道写入机制 编译过程

838

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

深度学习工具包 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 2025 A卷 100分)
下一篇: 华为OD机试 - 分割数组的最大差值 - 双指针(Python/JS/C/C++ 2025 A卷 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、付费专栏及课程。

余额充值