A.Sweet Problem

题目:甜蜜的问题

题意:你有三堆糖果:红色,绿色,蓝色
第一堆有r个糖果,第二堆有g个糖果,第三堆有b个糖果
每天都可以吃两个不同颜色的糖果,找出可以吃糖果的最大天数

分析:先排下序,如果最大堆大于等于其它两堆的和,那么答案是另外两堆的和,如果小于其它两堆的和,那么首先可以先消掉最大堆,另外两堆要分摊消掉的糖果,
其次还要将剩余的两堆互相消掉,因为要尽量得到最大天数,因此要将两堆分摊成相同的两堆。

#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;
int a[3];
int t;
int main()
{
    cin >> t;
    while (t--)
    {
        cin >> a[0] >> a[1] >> a[2];

        sort(a, a + 3);


        if (a[2] >= a[0] + a[1])
            printf("%d\n", a[0] + a[1]);
        else
        {
            //a[2] < a[0] + a[1]

            int res = 0;
            res += a[2];

            int t = (a[0] + a[1] - a[2]) / 2;
            res += t;
            printf("%d\n", res);
        }

    }


    return 0;
}

猜你喜欢

转载自www.cnblogs.com/pixel-Teee/p/11964094.html