L - Divide The Students

题目链接
A group of students has recently been admitted to the Faculty of Computer Sciences at the Berland State University. Now the programming teacher wants to divide them into three subgroups for practice sessions.

The teacher knows that a lot of programmers argue which language is the best. The teacher doesn’t want to hear any arguments in the subgroups, so she wants to divide the students into three subgroups so that no pair of students belonging to the same subgroup want to argue.

To perform this division, the teacher asked each student which programming language he likes. There are a students who answered that they enjoy Assembler, b students stated that their favourite language is Basic, and c remaining students claimed that C++ is the best programming language — and there was a large argument between Assembler fans and C++ fans.

Now, knowing that Assembler programmers and C++ programmers can start an argument every minute, the teacher wants to divide the students into three subgroups so that every student belongs to exactly one subgroup, and there is no subgroup that contains at least one Assembler fan and at least one C++ fan. Since teaching a lot of students can be difficult, the teacher wants the size of the largest subgroup to be minimum possible.

Please help the teacher to calculate the minimum possible size of the largest subgroup!

Input
The first line contains one integer t (1≤t≤5) — the number of test cases in the input. Then test cases follow.

Each test case consists of one line containing three integers a, b and c (1≤a,b,c≤1000) — the number of Assembler fans, Basic fans and C++ fans, respectively.

Output
For each test case print one integer — the minimum size of the largest subgroup if the students are divided in such a way that there is no subgroup that contains at least one Assembler fan and at least one C++ fan simultaneously.
Input

5
3 5 7
4 8 4
13 10 13
1000 1000 1000
13 22 7

Output

5
6
13
1000
14

Input

5
1 3 4
1000 1000 1
4 1 2
325 226 999
939 861 505

Output

3
667
3
517
769

Note
Explanation of the answers for the example 1:

The first subgroup contains 3 Assembler fans and 2 Basic fans, the second subgroup — 5 C++ fans, the third subgroup — 2 C++ fans and 3 Basic fans.
The first subgroup contains 4 Assembler fans, the second subgroup — 6 Basic fans, the third subgroup — 2 Basic fans and 4 C++ fans.
The first subgroup contains all Assembler fans, the second subgroup — all Basic fans, the third subgroup — all C++ fans.
The first subgroup contains all Assembler fans, the second subgroup — all Basic fans, the third subgroup — all C++ fans.
The first subgroup contains 12 Assembler fans and 2 Basic fans, the second subgroup — 1 Assembler fan and 13 Basic fans, the third subgroup — 7 Basic fans and 7 C++ fans.

题目大意

先给你一个数字 T 表示有T组数据,每组数据有三个数,分别表示 喜欢 Assembler 的人数,喜欢Basic的人数,喜欢C++的人数,让你帮他将这些人分成三组,要求每组人尽可能的多,输出人数最多的一组的人数,但是在分组的时候要注意喜欢Assembler的人不能喝喜欢C++的人一组;

解题思路

这个题的主要矛盾就是喜欢A的人和喜欢C的人,我们可以向找出喜欢这两种语言最多的人数为ma,和最少的人数为mi;然后让B再中间补充;我们可以分为三种情况来讨论;
1:当(ma+1)/2>b+mi;
至少的人数加上B的人数在一组,然后将最多的人数疯成两组;
2: 当 b特别小的时候
因为b特别小,如果直接求平均值那么会出现 ma和mi都会给b一组,那么是不合理的,但是我们怎么才能知道这种情况呢?我们用平均值(向下取整)和mi进行比较如果没有 mi 大那就说明如果直接均分会让 mi 也给 b 值,这种情况无论我们怎么分最多的人数都是 mi,的所以直接输出就好了
3:可以直接求平均值的
除了上面的两种情况后,剩下的咱们就可以直接求平均值了,注意求平均值的时候要向上取整;

代码

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,a,b,c;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b>>c;
        int min_=min(a,c);//a和c中最大的数
        int max_=max(a,c);//a和c中最小的数
        int x=(a+b+c)%3;
		if(x) x=1;
		int y=(a+b+c)/3;
		if(min_+b<=(max_)/2) cout<<(max_+1)/2<<"\n";//第一种情况,最大值直接分成两组;
		else if(y<min_) cout<<min_<<"\n";//第二组情况 
		else{
			cout<<y+x<<"\n";
		}
    }
    return 0;
}