python: Two wine bottles can change a bottle of wine; four corks can also change a bottle of wine. Calculate how many bottles of wine can you finally drink if you have n bottles of wine at first?

Known: two wine bottles can be exchanged for a bottle of wine; four corks can also be exchanged for a bottle of wine.

Calculate how many bottles of wine can you finally drink if you have n bottles of wine at first?

 

 1 #coding: utf-8
 2 n = int(input());
 3 wine, lid, bottle = n, n, n
 4 while lid>=4 or bottle>=2:
 5     a = 0
 6     b = 0 
 7     if lid>=4:
 8         a = int(lid/4)
 9         wine += a
10         lid = lid%4 + a
11     elif bottle>=2:
12         b = int(bottle/2)
13         wine += b
14         bottle = bottle%2 + b
15     lid += b
16     bottle +=a
17 print (wine)

test:

  Input: 3

  Output: 7

 

  Input: 4

  Output: 11

 

Guess you like

Origin www.cnblogs.com/y-yang/p/12691388.html