今晚的360第二题编程题

今晚的360第二题编程题,考完后改了一下,现在是对的吗?
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    int T;
    long r, g, b;
    vector<long> result;
    cin >> T;
    for (int i = 0; i < T; i++)
    {
        vector<long> num;
        long count = 0;
        cin >> r >> g >> b;
        num.push_back(r);
        num.push_back(g);
        num.push_back(b);
        sort(num.begin(), num.end());

        if (num[2] == 0)
        {
            count = 0;
        }
        else
        {
            if (2 * (num[0] + num[1]) <= num[2])
                count = num[0] + num[1];
            else
            {
                long min_num = num[0];

                long temp_max = 0;
                long temp1 = num[2] - num[0];
                long temp2 = num[1] - num[0];
                if (temp1 >= 2 * temp2)
                    temp_max = temp2;
                else
                    temp_max = temp1 / 2;
                count = min_num + temp_max ;
            }            
        }
        result.push_back(count);
    }    

    for (int i = 0; i < T; i++)
    {
        cout << result[i] << endl;
    }

    return 0;

}


#实习##笔试题目#
全部评论
AC代码 #include<iostream> #include<vector> #include<algorithm> #include<cmath> using namespace std; int main() {     int t;     cin>>t;     while(t--)     {         vector<long long >color;         long long  ans=0,temp;         for(int i=0;i<3;++i)         {             cin>>temp;             color.push_back(temp);         }         sort(color.begin(),color.end());         ans+=color[0];         ans+=min((color[1]+color[2]-2*color[0])/3,color[1]);         cout<<ans<<endl;     }     return 0; }
点赞 回复 分享
发布于 2018-04-01 13:51
某个oj的原题
点赞 回复 分享
发布于 2018-03-31 23:29
你这太乱了 不看啦 其实就两个 如果最小的两个和的2倍比最大的小 那就是最小的 两个和 否则就是3个的和除3 下取整
点赞 回复 分享
发布于 2018-03-31 22:37
感觉不太对吧,如果最后剩的两个数相同,那么最后的结果不太对吧
点赞 回复 分享
发布于 2018-03-31 22:03

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务