题解:UVA11689 Soda Surpler

· · 题解

题目大意

有一些空瓶子,可以用空瓶子换汽水。每喝一瓶汽水就会多一个空瓶子,题目给出需要要几个空瓶子换一瓶汽水,问你最多能喝几瓶汽水。

思路

模拟我们有 e+f 个空瓶子,每 c 个空瓶子可以换一瓶汽水,喝完后又有了一个空瓶子,然后又可以换汽水,一直换到没瓶子了为止。

代码

#include<bits/stdc++.h>
using namespace std;
int n;
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int e, f, c, ans = 0, sum;
        cin >> e >> f >> c;
        sum = e + f;
        while (sum >= c) {
            int s = sum / c;
            ans += s;
            sum = sum % c + s;
        }
        cout << ans << endl;
    }
    return 0;
}