思路:每次酒全部变空瓶,空瓶n瓶换1瓶,一个递推。
class Solution {
public:
int numWaterBottles(int numBottles, int numExchange) {
int an = 0;
int emptyBottom = 0;
while(numBottles > 0 || emptyBottom >= numExchange){
an += numBottles;
emptyBottom += numBottles;
numBottles = 0;
numBottles += emptyBottom / numExchange;
emptyBottom = emptyBottom % numExchange;
// cout << an << endl;
}
// an += numBottles;
return an;
}
};