华为OD机试真题-虚拟游戏理财-2023年OD统一考试(C卷)---Python3--开源

题目:
在这里插入图片描述

考察内容:
for + if + max
代码:

"""
题目分析:

投资额*回报率=投资回报
要在可接受范围内选择最优的投资方式获得最大回报

最多投资2个理财产品

输入:
产品数int; 总投资额int; 总风险int
产品投资回报率 list(int)
产品风险值序列  list(int)
最大投资额度序列 list(int)

输出:

投资额序列

eg:
5 100 10
10 20 30 40 50
3 4 5 6 10
20 30 20 40 30

0 30 0 40 0

5 100 3
10 20 30 40 50
3 4 5 6 10
20 30 20 40 30

20 0 0 0 0
思路:
条件:
投资回报最大;风险值小于X, 投资额小于N
"""
m, N, X = map(int, input().split())
# 投资回报率序列
a = list(map(int, input().split()))
# 风险值序列
b = list(map(int, input().split()))
# 最大投资额度序列
c = list(map(int, input().split()))

max_money = 0

res = []
# 循环产品数量
for i in range(m):
    for j in range(i+1, m):
        if N >= c[i] + c[j] and X >= b[i] + b[j]:
            temp = a[i]*c[i] + a[j]*c[j]
            max_money = max(max_money, temp)
            res = [i, j]
# 防止两个产品不满足风险值和总额,只能选一个产品
if not res:
    for i in range(m):
        if N >= c[i] and X >= b[i]:
            max_money = max(max_money, a[i]*c[i])
            res = [i]
# print(max_money, res)
res_money = list()
for i in range(len(c)):
    if i in res:
        res_money.append(c[i])
    else:
        res_money.append(0)
print(res_money)
### 华为OD模式题A及相关开发资料 华为OD模式下的主要考察候选人的编程能力、算法设计能力和逻辑思维能力。虽然具体的A题可能未完全公开,但基于已知的其他(如C、D、E),可以推测其考查范围和形式。 #### 1. **华为OD模式简介** OD模式(Outsourcing Dispatch)是由华为与外企德科合作推出的一种用工形式[^2]。该模式适用于定级在13至17级之间的候选人,属于华为储备人才计划的一部分。每会从OD项目中挑选表现优异的员工转为正式编制。 #### 2. **常见考点** 根据已有资料,华为OD通常涉及以下几个方面: - 数据结构:链表、栈、队列、树、图等基本数据结构的操作。 - 算法设计:排序算法、查找算法、动态规划、贪心算法等经典算法的应用。 - 编程实现:字符串处理、文件操作、矩阵运算等实际场景中的编码能力测- 综合应用:结合业务背景的实际问题解决,例如开源项目的热度计算[^3]。 #### 3. **假设的A题目分析** 尽管具体A题目尚未披露,以下是根据现有信息推测的一个典型题目: ##### 题目描述 某公司需要对一批商品进行分类管理。每种商品有以下属性: - 商品名称 `name` (字符串) - 销售数量 `sales` (整数) - 用户评分 `rating` (浮点数) 请编写程序完成以下功能: 1. 输入一组商品的数据; 2. 计算每个商品的综合得分 \( S \),其中 \( S = w_1 \times sales + w_2 \times rating \)。(\( w_1, w_2 \) 是给定权重) 3. 按照综合得分降序排列;如果得分相同,则按商品名称升序排列。 ##### 输入输出示例 **输入:** ```plaintext w1=0.8,w2=0.2 ProductA,100,4.5 ProductB,90,4.8 ProductC,100,4.2 ``` **输出:** ```plaintext ProductA,S=84.0 ProductB,S=83.2 ProductC,S=82.4 ``` ##### 实现代码 ```python def calculate_scores(products_data, weights): w1, w2 = map(float, weights.split(',')) products = [] for product_info in products_data: name, sales, rating = product_info.strip().split(',') score = float(sales) * w1 + float(rating) * w2 products.append((name.lower(), score)) # 排序规则:先按score降序,再按name升序 sorted_products = sorted(products, key=lambda x: (-x[1], x[0])) result = [] for name, score in sorted_products: result.append(f"{name},S={score:.1f}") return "\n".join(result) # 测用例 weights_input = "w1=0.8,w2=0.2" products_input = ["ProductA,100,4.5", "ProductB,90,4.8", "ProductC,100,4.2"] print(calculate_scores(products_input, weights_input)) ``` 上述代码实现了商品综合得分的计算以及排序功能。 #### 4. **备考建议** 为了更好地应对华为ODA,考生可以从以下几个方向入手准备: - 复习基础数据结构和常用算法。 - 提高Python/C++/Java等主流编程语言的熟练度。 - 参考历真题(如C、D、E)并模拟练习。 - 关注实际应用场景中的问题建模与优化方法。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值