zoukankan      html  css  js  c++  java
  • Codeforces Round #603 (Div. 2) A. Sweet Problem(数学)

    链接:

    https://codeforces.com/contest/1263/problem/A

    题意:

    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.

    思路:

    排序得到r >= g >= b
    考虑r >= g+b,答案是g+b
    否则让r,g,b三个相等
    首先让r=g,r减去r-g, b减去r-g(保证可行,r < g+b => b > r-g)
    再让r = g = b,r和g同时减去g-(b-(r-g)),三者最后为b+g-r
    考虑三个相等,即可。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        int a[3];
        int t;
        cin >> t;
        while(t--)
        {
            for (int i = 0;i < 3;++i)
                cin >> a[i];
            sort(a, a+3);
            if (a[2] >= a[1]+a[0])
                cout << a[1]+a[0] << endl;
            else
            {
                int ans = 0;
                ans += (a[2]-a[1])+(a[2]-a[0]);
                int t = a[0]-a[2]+a[1];
                ans += (3*t)/2;
                cout << ans << endl;
            }
        }
    
        return 0;
    }
    
  • 相关阅读:
    xx
    office 2016 下载链接
    Revit 2019 下载链接
    AE cc 2019 下载链接
    Premiere Pro cc 2019 下载链接
    Photoshop cc 2019 下载链接
    百度云单机版、软件包及教程
    Visual Studio 2017 软件包及教程
    归并排序:逆序对问题
    归并排序:小和问题
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12053774.html
Copyright © 2011-2022 走看看