题目链接: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;
}