题解:P15016 [UOI 2020 II Stage] 考试

· · 题解

P15016 [UOI 2020 II Stage] 考试

solution

按题意模拟,分三类讨论答案。

::::info[当 a = b 时]

即他答对了这道题,所以答案是 n + c

::::

::::info[当 a \ne ba \ne 0 时]

他没有留空,答错了这道题,扣除 \frac{c}{4} 分,所以答案为 n - \frac{c}{4}

:::warning[注意]

他的分数不能低于 0,所以需要特判。

:::

::::

::::info[当 a = 0 时] 他留空了这道题,所以不扣分,答案即为 n。 ::::

做完了。

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 n, a, b, c;
int solve() {
    if (a == b) {
        return n + c;
    }
    if (a != 0 && a != b) {
        if (n - c / 4 < 0) {
            return 0;
        }
        else {
            return n - c / 4;
        }
    }
    if (a == 0) {
        return n;
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t; t = 1;
    while (t--) {
        cin >> n >> a >> b >> c;
        cout << solve() << endl;
    }
    return 0;
}