题目描述
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can’t have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that cc of your students are coders, mm are mathematicians and xx have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer qq independent queries.
Input
The first line contains a single integer qq (1≤q≤1041≤q≤104) — the number of queries.
Each of the next qq lines contains three integers cc, mm and xx (0≤c,m,x≤1080≤c,m,x≤108) — the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
Output
Print qq integers — the ii-th of them should be the answer to the ii query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
Example
input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
output
1
3
0
0
1
3
Note
In the first example here are how teams are formed:
- the only team of 1 coder, 1 mathematician and 1 without specialization;
- all three teams consist of 1 coder and 2 mathematicians;
- no teams can be formed;
- no teams can be formed;
- one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren’t able to form any team;
- one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
题解
题意
有三种队员,分别擅长写代码、数学和其他。三个人组队,若一个队中至少有一个擅长写代码的人和一个擅长数学的人,则这个队伍是Perfect Team。已知三种队员的个数,求最多能组成多少个Perfect Team。
思路
首先,求出三个人一队最多能组成多少个队。
若队伍数量比min(擅长写代码的人数,擅长数学的人数)大,则Perfect Team的数量就是min(擅长写代码的人数,擅长数学的人数);
若队伍数量比min(擅长写代码的人数,擅长数学的人数)小,则Perfect Team的数量就是最多能组成的队伍数量。
代码
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
int q;
cin>>q;
ll c,m,x,Max,ans;
while(q--){
scanf("%lld%lld%lld",&c,&m,&x);
Max=ll(c+m+x)/3;
if(Max<min(c,m)){
ans=Max;
}else{
ans=min(c,m);
}
printf("%d\n",ans);
}
}