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

· · 题解

按照题意模拟即可。如果 a=b,输出 n+c。如果 a\neq 0 且 a\neq b,输出 n-\frac{c}{4},注意分数不能为负数,如果 n-\frac{c}{4}<0 要输出 0,也就是输出 0 与 n-\frac{c}{4} 的最大值。如果 a=0,输出 n。

代码

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ft first
#define sd second
#define fs(i,x,y) for(int i=(x);i<=(y);i++)
#define fj(i,x,y) for(int i=(x);i>=(y);i--)
signed main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);
    int n,a,b,c;
    cin>>n>>a>>b>>c;
    if(a==b)cout<<n+c;
    else if(a!=0&&a!=b)cout<<max(0ll,n-c/4);
    else cout<<n;
    return 0;
}