题解:B4467 分摊水费 / bill

· · 题解

B4467 分摊水费 / bill

solution

分支结构的应用。

::::info[当 a + b \ge 10 时]{open} 根据题意,小山和小西的水费都是 4 \times \frac{a + b}{2} = 2a + 2b 元。 :::: :::::info[当 a + b > 10 时]{open} 有两种情况需要再次分讨。

::::info[当 a > b 时] 即小山的水费大于小西的水费时,所以小山需要支付 4 \times 5 + 5 \times (a + b - 10) = 5a + 5b - 30 元,小西需要支付 4 \times 5 = 20 元。 :::: ::::info[当 a < b 时] 即小山的水费小于小西的水费时,所以小西需要支付 4 \times 5 + 5 \times (a + b - 10) = 5a + 5b - 30 元,小海需要支付 4 \times 5 = 20 元。 :::: :::::

做完了。

AC code

#include <bits/stdc++.h>
#define debug(a) cerr << (#a) << " = " << (a) << endl;
#define int long long
#define maxn 100010
#define endl '\n'
using namespace std;

int a, b;
void solve() {
    int sum = a + b;
    if (sum <= 10) {
        cout << 4 * sum / 2.0 << " " << 4 * sum / 2.0 << endl;
    }
    else if (sum > 10) {
        if (a > b) {
            cout << 4 * 5 + 5 * (sum - 10) << " " << 4 * 5 << endl;
        }
        else {
            cout << 4 * 5 << " " << 4 * 5 + 5 * (sum - 10) << endl;
        }
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t; t = 1;
    while (t--) {
        cin >> a >> b;
        solve();
    }
    return 0;
}