360笔试——春招

沫璃邀请她的朋友参加周末的派对。沫璃买了3种颜色的气球,现在她要有这些气球来装饰餐桌,每个餐桌只用恰好3个气球装饰,要求3个气球的颜色不能完全一样,可以是2种或者1种颜色。沫璃想知道这些气球最多能装饰多少张餐桌。
输入:
第一行一个数T(T<=100),表示数据组数。
对于每组数据,第一行3个整数r,g,b,分别表示三种颜色的气球个数 (0<=r, g, b<=2*10^9)
输出:
对于每组数据,输出一行,一个整数表示最多能装饰的餐桌数量。

样例输入:
2
5 4 3
2 3 3
样例输出:
4
2

#include<iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int r,g,b;
    int Max,Min,mins;
    while(n>0)
    {
        cin>>r>>g>>b;
        if(r>g){
            mins=g;
            if(r>b){
                Max=r;
                mins+=b;
                if(b>g){
                    Min=g;
                }
                else{
                    Min=b;
                }
            }
            else{
                Max=b;
                Min=g;
                mins+=r;
            }
        }
        else{
            mins=r;
            if(g>b){
                Max=g;
                mins+=b;
                if(b>r){
                    Min=r;
                }
                else{
                    Min=b;
                }
            }
            else{
                Max=b;
                Min=r;
                mins+=g;
            }
        }

        if(Max>=mins*2){
            cout<<mins<<endl;
        }
        else{
            int k=((Max+mins)-(Max*2-mins))/3;
            if((Max-k)>(mins-2*k)*2){
                cout<<(mins-k)<<endl;
            }
            else{
                cout<<((Max-k   )/2+k)<<endl;
            }
        }
        n--;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_20366761/article/details/79799684