题解 | #汽水瓶#

汽水瓶

https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f

ins = []
result = []
dp = []
while True:
    s = input()
    if s == '0':
        break
    ins.append(int(s))
    dp.append( (int(s)-1)/2) # 记录当前空瓶最少可以换多少个
# x表示要换到多少瓶 f(x)表示需要多少空瓶,题目给的是有多少空瓶,因此我们只需要计算大概可以换到多少瓶;
# f(1) = 3
# f(2) = 5
# f(3) = 7
# f(4) = 9
# 得到f(x) = 2*x + 1
for item in dp:
    if item - int(item) >= 0.5: # 这里表示最后有剩余2瓶的情况,因此还可以借一瓶再换一瓶
        print(int(item)+1)
        continue
    print(int(item))
 

全部评论

相关推荐

Java转测开第一人:这种就是饼 把应届当廉价劳动力用完然后丢掉
你觉得今年秋招难吗
点赞 评论 收藏
分享
给🐭🐭个面试机会...:我擦seed✌🏻
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务