1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| class Solution { public: int maxBottlesDrunk(int numBottles, int numExchange) {
int full_bottles = numBottles; int empty_bottles = 0; int num_exchange = numExchange; int bottle_drunk = 0;
while (full_bottles > 0 || empty_bottles >= num_exchange) { bottle_drunk += full_bottles; empty_bottles += full_bottles; full_bottles = 0; while (empty_bottles >= num_exchange) { empty_bottles -= num_exchange; num_exchange++; full_bottles++; } } return bottle_drunk; } };
|