博客
关于我
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/

你可能感兴趣的文章
npm报错TypeError: this.getOptions is not a function
查看>>
npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
查看>>
npm淘宝镜像过期npm ERR! request to https://registry.npm.taobao.org/vuex failed, reason: certificate has ex
查看>>
npm版本过高问题
查看>>
npm的“--force“和“--legacy-peer-deps“参数
查看>>
npm的安装和更新---npm工作笔记002
查看>>
npm的常用操作---npm工作笔记003
查看>>
npm的常用配置项---npm工作笔记004
查看>>
npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
查看>>
npm编译报错You may need an additional loader to handle the result of these loaders
查看>>
npm设置淘宝镜像、升级等
查看>>
npm设置源地址,npm官方地址
查看>>
npm设置镜像如淘宝:http://npm.taobao.org/
查看>>
npm配置安装最新淘宝镜像,旧镜像会errror
查看>>
NPM酷库052:sax,按流解析XML
查看>>
npm错误 gyp错误 vs版本不对 msvs_version不兼容
查看>>
npm错误Error: Cannot find module ‘postcss-loader‘
查看>>
npm,yarn,cnpm 的区别
查看>>
NPOI
查看>>
NPOI之Excel——合并单元格、设置样式、输入公式
查看>>