鱼C论坛

 找回密码
 立即注册
查看: 1293|回复: 2

[已解决]皮皮小发

[复制链接]
发表于 2018-1-27 19:18:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. def drink(water,cup,bottle):
  2.     if water<1 and cup <3  and bottle <2:
  3.         return 0
  4.     else:
  5.         waters = (cup//3 + bottle//2)
  6.         cups = cup%3 + (cup//3 + bottle//2)
  7.         bottles = bottle%2 + (cup//3 + bottle//2)
  8.         return drink(waters,cups,bottles)+water

  9. print(drink(20,20,20))

  10. def drink(water,cup,bottle):
  11.     if water<1 and cup <3  and bottle <2:
  12.         return 0
  13.     else:
  14.         waters = (cup//3 + bottle//2)
  15.         cup = cup%3 + (cup//3 + bottle//2)
  16.         bottles = bottle%2 + (cup//3 + bottle//2)
  17.         return drink(waters,cup,bottles)+water

  18. print(drink(20,20,20))
复制代码

为什么两段代码只差一个cups,打出来的结果却不一样
最佳答案
2018-1-27 19:33:53
bottles = bottle%2 + (cup//3 + bottle//2) 关键就在这一步。

cups 改一下不就一样了。
cups = cup%3 + (cup//3 + bottle//2)
bottles = bottle%2 + (cups//3 + bottle//2)  
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-1-27 19:26:01 | 显示全部楼层
cups = cup%3 + (cup//3 + bottle//2)
        bottles = bottle%2 + (cup//3 + bottle//2)第一个
cup = cup%3 + (cup//3 + bottle//2)
        bottles = bottle%2 + (cup//3 + bottle//2)第二个
两个cup已经不一样了,botlle能一样,越迭代越不一样
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-1-27 19:33:53 | 显示全部楼层    本楼为最佳答案   
bottles = bottle%2 + (cup//3 + bottle//2) 关键就在这一步。

cups 改一下不就一样了。
cups = cup%3 + (cup//3 + bottle//2)
bottles = bottle%2 + (cups//3 + bottle//2)  
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-3-6 11:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表