题目描述
时间限制:1s;空间限制:256MB
You have three piles of candies: red, green and blue candies:
- the first pile contains only red candies and there are r candies in it,
- the second pile contains only green candies and there are g candies in it,
- the third pile contains only blue candies and there are b candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
输入
The first line contains integer t (1≤t≤1000) — the number of test cases in the input. Then t test cases follow.
Each test case is given as a separate line of the input. It contains three integers r, g and b (1≤r,g,b≤108) — the number of red, green and blue candies, respectively.
输出
Print t integers: the i-th printed integer is the answer on the i-th test case in the input.
样例
input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
output
1
2
2
10
5
9
题意分析
q组数据,每组给定三个正数,每次从中选两个数减一,问最多经过几次使得这三个数中第一次出现0
C++代码
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
int q;
scanf("%d", &q);
while (q --) {
int r, g, b;
scanf("%d%d%d", &r, &g, &b);
// 最小值,最大值,中间值
// 思路就是将中间值分配到最小值和最大值上,使得这两个值的大小尽可能接近
int mi = min(r, min(g, b)), ma = max(r, max(g, b)), mid = r + g + b - mi - ma;
if (mi + mid <= ma) mi += mid;
else {
int tmp = mi + mid - ma;
mi += mid;
mi -= tmp / 2 + tmp % 2;
ma += tmp / 2;
}
printf("%d\n", mi);
}
return 0;
}