时间轴

2025-10-02

init


题目:

总是喝完所有水,如果没水就交换

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) {
// drink
bottle_drunk += full_bottles;
empty_bottles += full_bottles;
full_bottles = 0;
// exchange
while (empty_bottles >= num_exchange) {
empty_bottles -= num_exchange;
num_exchange++;
full_bottles++;
}
}
return bottle_drunk;
}
};