链接:

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. 【数据结构与算法】线性表操作(C++)

    #include <stdio.h> #define maxSize 100 //定义整型常量maxSize值为100 /*顺序表的结构体定义*/ typedef struct SqLis ...

  2. Luogu - P1018 乘积最大 - 题解

    原文:https://www.luogu.org/problemnew/solution/P1018?page=7 题目:P1018[乘积最大] 前言: 这题的正解理论上说是DP,可是由于民间数据太水 ...

  3. python之路——阅读目录

    阅读目录 希望大家多多交流,有错误的地方请随时指正,笔记记得可能有点杂 一.python入门 计算机基础 编程语言发展史和python安装  二.数据类型.字符编码.文件处理 python基础数据类型 ...

  4. FusionInsight大数据开发---Kafka应用开发

    Kafka应用开发 了解Kafka应用开发适用场景 熟悉Kafka应用开发流程 熟悉并使用Kafka常用API 进行Kafka应用开发 Kafka的定义Kafka是一个高吞吐.分布式.基于发布订阅的消 ...

  5. 使用 Navicat Premium 将 sql server 的数据库迁移到 mysql 的数据库中

    步骤1,打开 Navicat Premium ,创建一个新的 mysql 数据库: 步骤2,选中刚刚创建的新数据库 ,双击选中后点击导入向导,然后选择 "ODBC",并点击下一步 ...

  6. String.Operation

    // 字符串切割 StringField.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

  7. springboot maven项目转gradle的完整方法

    1.maven转gradle的方法:在项目根目录下,使用命令行工具,输入如下内容: gradle init --type.pom 2.springboot项目的 build.gradle内容示例如下( ...

  8. 2019 找钢网java面试笔试题 (含面试题解析)

      本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.找钢网等公司offer,岗位是Java后端开发,因为发展原因最终选择去了找钢网,入职一年时间了,也成为了面试官 ...

  9. Map接口---Day20

    Map接口概述: 现实生活中,我们常会看到这样的一种集合:IP地址与主机名,身份证号与个人,系统用户名与系统用户对象等, 这种一一对应的关系,就叫做映射.Java提供了专门的集合类用来存放这种对象关系 ...

  10. 玩转zynq7020之风速风向测量实战项目

    本文是用米尔zynq7020开发板(Z-turn broad)风速风向测量实战项目. 这次项目是以测量风速风向为目标的产品,由于传统的风杯有很大的缺陷,在零下20度,结冰后不能使用,还有启动风速等等, ...