【CODEFORCES】 C. Table Decorations
1 second
256 megabytes
standard input
standard output
You have r red, g green
and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table
shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?
Your task is to write a program that for given values r, g and b will
find the maximum number t of tables, that can be decorated in the required manner.
The single line contains three integers r, g and b (0 ≤ r, g, b ≤ 2·109)
— the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.
Print a single integer t — the maximum number of tables that can be decorated in the required manner.
5 4 3
4
1 1 1
1
2 3 3
2
In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb",
"brr", "rrg", where "r",
"g" and "b" represent the red, green and blue balls, respectively.
题解:这一题是一道贪心。策略是优先取最小的那堆,然后最大堆拿2个。看到题目数据非常大。不可能模拟。所以就从2堆的基础上推出一个公式:当最小的两堆相加乘以2比最大的那堆大时,结果就是3堆相加在整除3。否则就是两堆最小堆的和。(由于每次拿的都是3的倍数,并且最小的两堆并不能在最大的堆被拿完钱拿完,所以结果一定是相加后整除3)
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib> using namespace std; long long r,g,b,ans; int main()
{
scanf("%I64d%I64d%I64d",&r,&g,&b);
if (r>g) swap(r,g);
if (r>b) swap(r,b);
if (g>b) swap(g,b);
if ((r+g)*2<=b)
{
printf("%I64d\n",r+g);
return 0;
}
else ans=(r+g+b)/3;
printf("%I64d\n",ans);
return 0;
}
【CODEFORCES】 C. Table Decorations的更多相关文章
- 【Codeforces】Round #488 (Div. 2) 总结
[Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...
- 【CF662C】Binary Table(FWT)
[CF662C]Binary Table(FWT) 题面 洛谷 CF 翻译: 有一个\(n*m\)的表格(\(n<=20,m<=10^5\)), 每个表格里面有一个\(0/1\), 每次可 ...
- 【CF662C】Binary Table 按位处理
[CF662C]Binary Table 题意:给你一个$n\times m$的01网格,你可以进行任意次操作,每次操作是将一行或一列的数都取反,问你最多可以得到多少个1? $n\le 20,m\le ...
- 【Codeforces】Round #491 (Div. 2) 总结
[Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at fir ...
- 【CodeForces】601 D. Acyclic Organic Compounds
[题目]D. Acyclic Organic Compounds [题意]给定一棵带点权树,每个点有一个字符,定义一个结点的字符串数为往下延伸能得到的不重复字符串数,求min(点权+字符串数),n&l ...
- 【Codeforces】849D. Rooter's Song
[算法]模拟 [题意]http://codeforces.com/contest/849/problem/D 给定n个点从x轴或y轴的位置p时间t出发,相遇后按对方路径走,问每个数字撞到墙的位置.(还 ...
- 【CodeForces】983 E. NN country 树上倍增+二维数点
[题目]E. NN country [题意]给定n个点的树和m条链,q次询问一条链(a,b)最少被多少条给定的链覆盖.\(n,m,q \leq 2*10^5\). [算法]树上倍增+二维数点(树状数组 ...
- 【CodeForces】925 C.Big Secret 异或
[题目]C.Big Secret [题意]给定数组b,求重排列b数组使其前缀异或和数组a单调递增.\(n \leq 10^5,1 \leq b_i \leq 2^{60}\). [算法]异或 为了拆位 ...
- 涉及到【分页】的table的请求模式
step:1 点击分页器的内容 trigger事件句柄 (pagination, filters, sorter) => {//或者(page, pageSize)等 this.props.on ...
随机推荐
- 洛谷 P2415 集合求和【数学公式/模拟】
给定一个集合s(集合元素数量<=30),求出此集合所有子集元素之和. 输入输出格式 输入格式: 集合中的元素(元素<=1000) 输出格式: 和 输入输出样例 输入样例#1: 2 3 输出 ...
- (寒假开黑gym)2018 USP Try-outs
layout: post title: (寒假开黑gym)2018 USP Try-outs author: "luowentaoaa" catalog: true tags: m ...
- FCL研究-集合- System.Collections 接口和对象集合
[目录] 发现自己已经有很长一段时间写代码没什么进步了,随便读读FCL的源码,看看之前一直用的方法是如何实现的,也顺便提高下自己.FCL很是庞大,很难下口,于是用最笨的办法,先看常见的命名空间,逐个展 ...
- 静态NAT地址转换
1.配置路由器端口ip(两个端口需要设置两个网段) Router(config)#inter f0/1 Router(confiog-if)#ip add 202.1.1.2 255.255.255. ...
- Java 和 数据库两种方式进行加锁
java方式: publicstatic synchronized int generate(StringtableName){ Stringsql = "select value from ...
- Node.js 调用 restful webservice
如何构建一个restful web service参考原来的文章 http://www.cnblogs.com/ericnie/p/5212748.html 直接用原来的项目编译好像有问题,此处耗费1 ...
- 在Oracle Enterprise Linux R5U7上安装Oracle 11gr2数据库
折腾了好几次,经验是: 包的安装 在安装包里,需要把开发方面的安装包都装上. 另外安装完成后,需要安装的包包括: cd /media/cdrom/Server rpm -Uvh binutils-2. ...
- linux内核分析笔记----上半部与下半部(下)
接着上节的来,我们在上节说了软中断和tasklet,那这最后就是工作队列了哦.. 工作队列和前面讨论的其他形式都不相同,它可以把工作推后,交由一个内核线程去执行----该工作总是会在进程上下文执行.这 ...
- Linux内核分析(九)——总结篇
序:写在前面的话 本次内容作为Linux内核的总结内容,主要涉及对Linux系统的总体的一些理解,同时将之前的一些总结贴出来作为大家的一个索引,希望笔者的博客能对和笔者一样的菜鸟有一些帮 ...
- cpp面向对象编程
如下图,先建好文件, 这里用的是Visual studio 2010 当然也可以用eclipse for cpp,如下图: AbstractShape.h #ifndef ABSTRACTSHAPE_ ...