惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
MyScale Blog
MyScale Blog
博客园 - 【当耐特】
I
InfoQ
腾讯CDC
aimingoo的专栏
aimingoo的专栏
L
LangChain Blog
人人都是产品经理
人人都是产品经理
D
DataBreaches.Net
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
Vercel News
Vercel News
C
Check Point Blog
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
D
Docker
MongoDB | Blog
MongoDB | Blog
量子位
博客园_首页

博客园 - coffee~

在微信端使用Openclaw的简单配置方法--WorkBuddy 使用Termux+Proot-distro+Ubuntu+zsh在手机端配置安装Openclaw,使用Skillhub安装skill, 接入企业微信 npm切换下载源为国内的镜像源 一加13刷氧系统--OxygenOS 15 for oneplus 13 Playwright使用Typescript实现在测试case文件中调用另一个文件中的方法 Cypress实现拖拽 git基本命令 使用Playwright进行Web页面UI自动化测试 Python获取星期几 cd命令切换目录简写 win10在任意位置安装Linux子系统WSL Ubuntu pixel刷机没有退出谷歌账号,无法跳过开机验证 Python在一个文件中引用另一个文件的所有变量 pycharm给代码批量添加tab/取消添加tab 用Pycharm把浏览器复制出来的headers/参数给字段和值分别加单引号 Python requests.get所有参数顺序、Python requests.post所有参数顺序 windows使用快捷按键进行截图、录屏 Python由字符串生成字典 Python生成随机数 Python安装包国内镜像源 QQ飞车手游UI自动化测试尝试
3个瓶盖可以兑换一瓶饮料,买了n瓶饮料,一共可以喝到多少瓶
coffee~ · 2022-03-30 · via 博客园 - coffee~
#3个瓶盖可以兑换一瓶饮料,买了n瓶饮料,一共可以喝到多少瓶
def get_drink(n):
total = 0
left = 0
while n>=3:
total +=n
left += n%3
if left>=3:
total +=left//3
left = left%3
n = n//3
return total

t = get_drink(100)
print(t)

也可以写成:

def get_drink(n):
total = 0
left = 0
while n>=3:
total +=n
left += n%3
if left>=3:
add, left = divmod(left, 3)
total+= add
n = n//3
return total

t = get_drink(1200)
print(t)

也可以写成

def get_drink(n):
total = 0
left = 0
while n>=3:
total +=n
n, left_add = divmod(n, 3)
left += left_add
if left>=3:
total_add, left = divmod(left, 3)
total+= total_add
return total

print(get_drink(100))

注意:

print(5//4)
#结果为1,取到商的整数
print(5/4)
#结果为1.25
a, b = divmod(5, 4)
print(a, b)
#结果为1,1,divmod(a,b)可以取到商的整数