码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #603 (Div. 2) A. Sweet Problem(数学)

时间:2019-12-17 13:20:32      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:ORC   ima   ble   cout   str   die   https   round   std   

链接:

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;
}

Codeforces Round #603 (Div. 2) A. Sweet Problem(数学)

标签:ORC   ima   ble   cout   str   die   https   round   std   

原文地址:https://www.cnblogs.com/YDDDD/p/12053774.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!