|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- def drink(water,cup,bottle):
- if water<1 and cup <3 and bottle <2:
- return 0
- else:
- waters = (cup//3 + bottle//2)
- cups = cup%3 + (cup//3 + bottle//2)
- bottles = bottle%2 + (cup//3 + bottle//2)
- return drink(waters,cups,bottles)+water
- print(drink(20,20,20))
- def drink(water,cup,bottle):
- if water<1 and cup <3 and bottle <2:
- return 0
- else:
- waters = (cup//3 + bottle//2)
- cup = cup%3 + (cup//3 + bottle//2)
- bottles = bottle%2 + (cup//3 + bottle//2)
- return drink(waters,cup,bottles)+water
- print(drink(20,20,20))
复制代码
为什么两段代码只差一个cups,打出来的结果却不一样
bottles = bottle%2 + (cup//3 + bottle//2) 关键就在这一步。
cups 改一下不就一样了。
cups = cup%3 + (cup//3 + bottle//2)
bottles = bottle%2 + (cups//3 + bottle//2)
|
|