CF 1792B

##CF 1792B
原题链接: https://codeforces.com/problemset/problem/1792/B

题目不难,但是数据很恶心,很容易超时的,所以基本上是不能用for循环来写,尽量全用if else 语句,基本上O(1)能过的;
唯一要注意的是,表面上有两个人,但是只要看一个人的就行,因为有一个人一直是最低的

#include<bits/stdc++.h>

using namespace std;
const int N = 200010;
typedef long long ll;

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		ll a, b, c, d;
		//用res来记录情绪最低的那一个人的情绪数值
		ll ans = 0, res=0;
		cin >> a >> b >> c >> d;
		ans += a;
		res += a;
		//如果没有两个都喜欢的情绪,那肯定后面无论讲什么都会有一个人情绪
		//为负,所以上只可能讲一个
		if (a == 0)
		{
			cout << 1 << endl;
			continue;
		}
		//我们可以一人讲一个喜欢的,只要取他们的最小值就是相当于两个人的情绪
		//不变但是笑话都变多,这样也是最经济的选法
		ans += (min(b, c) * 2);
		//接下来我们要判断情绪最低的人会不会情绪为负
		int te = abs(b - c);
		//会
		if (te > res)
		{
			//注意是为负所以加一,结束运算
			ans += res+1;
			//cout << res << endl;
			cout << ans << endl;
			continue;
		}
		//不会
		else
		{
			
			res -= te;
			ans += te;
		}
		//继续判断
		if (res >= d)
		{
			ans += d;
		}
		else
		{
			//同上
			ans += res+1;
		}
		cout << ans << endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值