博客
关于我
python笔记1-用python解决小学生数学题
阅读量:466 次
发布时间:2019-03-06

本文共 712 字,大约阅读时间需要 2 分钟。

为了找出面值为6角、7角和8角的邮票的最大不可支付邮资,我们可以按照以下步骤进行:

生成所有可能的邮票组合

使用三个邮票面值,每种邮票最多使用50张,计算所有可能的邮资组合。

排序和去重

将所有可能的邮资排序并去重,得到一个连续的邮资范围。

找出最大不可支付邮资

检查从1角开始的邮资是否存在缺口,找出最大的缺口处的邮资。

代码实现

import itertoolsa, b, c = 6, 7, 8t = 50# 生成所有可能的邮票组合combinations = []for counts in itertools.product(range(t + 1), repeat=3):    total = a * counts[0] + b * counts[1] + c * counts[2]    combinations.append(total)# 去重并排序unique = sorted(list(set(combinations)))# 找出最大的不可支付邮资max_paid = unique[-1] if unique else 0max_incap = 0for i in range(1, max_paid + 1):    if i not in unique:        max_incap = i        breakif max_incap == 0:    print("所有邮资都可以支付,最大的不可支付邮资是:0元")else:    print("最大的不可支付邮资是:%s元" % max_incap)

结果

通过上述步骤,我们发现最大的不可支付邮资为17角,即1.7元。

转载地址:http://jkmbz.baihongyu.com/

你可能感兴趣的文章
nmap指纹识别要点以及又快又准之方法
查看>>
Nmap渗透测试指南之指纹识别与探测、伺机而动
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>