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

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

时间: 2024-10-08 03:06:52

Codeforces Round #603 (Div. 2) A. Sweet Problem(数学)的相关文章

Codeforces Round #196 (Div. 2) B. Routine Problem

screen 尺寸为a:b video 尺寸为 c:d 如果a == c 则 面积比为 cd/ab=ad/cb (ad < cb) 如果b == d 则 面积比为 cd/ab=cb/ad  (cb < ad) 如果不相等时 如果a/b > c/d,则ad/bd > cb/db 则(ad > cb) screen尺寸可为 ad:bd, video的尺寸可为 cb:db 面积比为:cb*db/ad*bd = cb/ad (ad > cb) 如果a/b < c/d,则a

Codeforces Round #112 (Div. 2) C Another Problem on Strings

题目链接:Codeforces Round #112 (Div. 2) C Another Problem on Strings 题意:给出一个只含0,1的序列,求序列中和为n的子序列有多少个. 思路:预处理出序列的前缀和,然后枚举序列时,记录(vis)该位置之前已有的前缀和,再查询(sum[i]-n)的个数,即以该位置为结束的子序列和为n的个数. 注意:vis数组中0应该始终存在,初始化vis[0]=1(why?,因为sum[i]本身就等于n算一个方法数). 举一反三:类似的就已经可以得到,任

Codeforces Round #603 (Div. 2) E. Editor 线段树

E. Editor The development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text. Your editor consists of a line with infinite length and cursor, which points to the current character. Please note that

Codeforces Round #603 (Div. 2) E. Editor(线段树)

链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text. Your editor consists of a line with infinite length and cursor, which point

Codeforces Round #603 (Div. 2)

传送门 感觉脑子还是转得太慢了QAQ,一些问题老是想得很慢... A. Sweet Problem 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/29 22:36:19 */ #include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <set> #include <ma

Codeforces Round #603 (Div. 2)E

http://codeforces.com/contest/1263/problem/E 题意:求合法的括号序列 #include<bits/stdc++.h> using namespace std; typedef long long ll; #define lson root<<1,l,midd #define rson root<<1|1,midd+1,r #define pb push_back const int inf=0x3f3f3f3f; const

Codeforces Round #603 (Div. 2) B. PIN Codes

链接: https://codeforces.com/contest/1263/problem/B 题意: A PIN code is a string that consists of exactly 4 digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0. Polycarp has n (

Codeforces Round #603 (Div. 2) C. Everyone is a Winner! (数学)

链接: https://codeforces.com/contest/1263/problem/C 题意: On the well-known testing system MathForces, a draw of n rating units is arranged. The rating will be distributed according to the following algorithm: if k participants take part in this event, t

codeforces Round #320 (Div. 2) C. A Problem about Polyline(数学)

解题思路: 我们可以发现这样的一个规律: (1)首先b一定要小于a,否则无论如何曲线也无法通过(a,b); (2)设int k=a/b, 如果k为奇数,说明这个点在上图的绿色的线上, 没关系,我们让 k+=1:这样的话一定有(0,0), (a,b)这两点确定的直线的 斜率1/k介于(1/(k-1),  1/(k+1))之间,那么我们可以通过缩小(或者放大)X的值,使得第 k/2 个周期块 斜率为-1的那条边经过(a, b).此时 的X值就是最小的! (3)如果(a,b)在第 k/2 个周期块 斜