跳到正文

题解

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

limaotong约 1 分钟
原文

这是 2026年1月25日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

收录
2026年1月25日
更新
2026年1月25日
篇幅
约 1 分钟
题目
P15016

版本

  1. v2当前
  2. v1

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

代码

C++
#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;
}