codeforces 1221C Perfect Team(数学)

题目链接:https://vjudge.net/problem/CodeForces-1221C

题意:

有三种队员,擅长写代码,擅长数学,和擅长其他的。现三个人组队,如果三个队员中至少 一个人擅长写代码,一个人擅长数学,那么这个队伍就是一个 Perfect Team,给出三种人的个数,问最多能有多少个Perfect Team

思路:

我的思路是,分情况讨论

1. 三种队员都有

2. 只有擅长code和math的队员

3. 缺code或math的队员

大佬的思路 ans = min{a, b, (a+b+c)%3}

code:

#include <algorithm>
#include <iostream>

using namespace std;
typedef long long LL;

int fun1(int &c, int &m, int &x)    // 三种队友都有
{
	int temp = min(c, m);    // 取代码和数学较少的一个
	if(c > temp){
		x += c - temp;
		c = temp;
	}
	else{
		x += m - temp;    // 多余的假设为其他人
		m = temp;
	}
		
	if(x >= temp)    // 如果其他类更多
	{
		x -= temp;
		c -= temp;
		m -= temp;
		return temp;
	}
	else
	{
		int tempx = x;
		c -= x;
		m -= x;
		x = 0;
		return tempx;
	}
}

int fun2(int &c, int &m, int &x)    // x为0
{
	int res = 0;
	res = c / 3 * 2;
	if(c%3 == 2)
		res ++;
	return res;
}
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int c, m, x;
		cin >> c >> m >> x;
		LL ans = 0;
		if(c ==0 || m == 0)
			ans = 0;
		else
		{
			while((x !=0 && c != 0 && m != 0) || (x == 0 && c != m && c+m >= 3))
			{
				ans += fun1(c, m, x);
			}
	//		cout << c << " " << m << " " << x << endl;
			ans += fun2(c, m, x);
		}
		
		cout << ans << endl;
		
	}
	
	return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值