链接:

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(数学)的更多相关文章

  1. Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题

    Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...

  2. Codeforces Round #603 (Div. 2) A. Sweet Problem 水题

    A. Sweet Problem the first pile contains only red candies and there are r candies in it, the second ...

  3. Codeforces Round #367 (Div. 2) C. Hard problem

    题目链接:Codeforces Round #367 (Div. 2) C. Hard problem 题意: 给你一些字符串,字符串可以倒置,如果要倒置,就会消耗vi的能量,问你花最少的能量将这些字 ...

  4. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  5. 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 ...

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

    链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...

  7. Codeforces Round #603 (Div. 2)

    传送门 感觉脑子还是转得太慢了QAQ,一些问题老是想得很慢... A. Sweet Problem 签到. Code /* * Author: heyuhhh * Created Time: 2019 ...

  8. Codeforces Round #603 (Div. 2) (题解)

    A. Sweet Problem (找规律) 题目链接 大致思路: 有一点瞎猜的,首先排一个序, \(a_1>a_2>a_3\) ,发现如果 \(a_1>=a_2+a_3\) ,那么 ...

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

    #include <cstdio> #include <algorithm> using namespace std; int main() { int t; scanf(&q ...

随机推荐

  1. SpringBoot 基础(一)

    目录 SpringBoot 基础(一) 一.简介 二.重要注解 三.基本应用开发 1. lombok的使用 2. SpringBoot 的参数传递 3. 对象参数校验 4. 静态资源 四.Spring ...

  2. 【mysql】mysql5.7支持的json字段查询【mybatis】

    mysql5.7支持的json字段查询 参考:https://www.cnblogs.com/ooo0/p/9309277.html 参考:https://www.cnblogs.com/pfdltu ...

  3. 基于Mybatis-Plus实现自动化操作创建时间和修改时间

    引入 在实际开发中,总会避免不了操作数据库,而在数据库中每个表都会有create_time和update_time字段记录操作时间,我们在操作这两个时间的时候也可能会出现不一致的情况,或者说这两个字段 ...

  4. DES加密 java与.net可以相互加密解密两种方法

    DES加密 java与.net可以相互加密解密两种方法 https://www.cnblogs.com/DrWang/archive/2011/03/30/2000124.html sun.misc. ...

  5. c#创建windows服务(代码方式安装、启动、停止、卸载服务)

    转载于:https://www.cnblogs.com/mq0036/p/7875864.html 一.开发环境 操作系统:Windows 10 X64 开发环境:VS2015 编程语言:C# .NE ...

  6. HDU2577 How to Type

    题目链接 一道DP问题 定义dp[i][j]为敲完第i个字母的最小花费,j=1代表Caps Lock打开,j=0代表Caps Lock关闭,则有: 如果第i个字母为大写: dp[i][1]=min(d ...

  7. java.net.URLEncoder对中文的编码和解码

    // java.net.URLEncoder对中文的编码和解码String str = URLEncoder.encode("测试字符串", "utf-8"); ...

  8. 阿里巴巴Java开发手册更新了!

    自2017年,<阿里巴巴Java开发手册>发布,现已有超过260万位工程师下载及查阅手册,在数以千计的企业应用,手册成为受业界认可的开发规范. 昨天,<Java开发手册>再次更 ...

  9. word,excel,ppt转pdf

    第一步 需要下载jar包和jacob-1.14.3-x64.dll * <dependency> * <groupId>net.sf.jacob-project</gro ...

  10. AI涉及到数学的一些面试题汇总

    [LeetCode] Maximum Product Subarray的4种解法 leetcode每日解题思路 221 Maximal Square LeetCode:Subsets I II (2) ...