【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 ...
随机推荐
- (15)python 数据库连接
python连接mysql两种方法 一.python官网提供的 MySQL-python 软件 下载地址 https://pypi.python.org/pypi/MySQL-python/1.2.5 ...
- 【线段树】Gym - 100507C - Zhenya moves from parents
线段树每个结点维护两个值,分别是这个区间的 负债 和 余钱. 按时间顺序从前往后看的时候,显然负债是单调不减的. 按时间顺序从后往前看的时候,显然余钱也是单调不减的,因为之前如果有余钱,可能会增加现在 ...
- 【后缀数组】【线段树】poj3974 Palindrome
考虑奇数长度的回文,对于字符串上的每个位置i,如果知道从i开始的后缀和到i为止的前缀反转后的字符串的lcp长度的话,也就知道了以第i个字符为对称中心的最长回文的长度了.因此,我们用在S中不会出现的字符 ...
- 【强连通分量缩点】【记忆化搜索】bzoj1589 [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果
缩成DAG f(i)表示以i为起点的最长路 #include<cstdio> #include<cstring> #include<algorithm> #incl ...
- 【最短路】【spfa】【最小割】【Dinic】bzoj1266 [AHOI2006]上学路线route
原问题等价于断掉一些边,让原来所有的最短路全都无法联通S和T. 先求最短路,然后把在最短路上的边(dis[u[i]]+w[i]==dis[v[i]])加入新图里,跑最小割.显然. 注意是无向图. #i ...
- Linux虚拟机小问题解决方法系列
1)使用虚拟机的过程中,会碰到虚拟机占用的空间越来越大的情况,即使删除了虚拟机里的文件,磁盘空间还是似乎还是没有释放,使用“vmware-vdiskmanager”工具解决.解决方法在这里:参考.合并 ...
- Asp.Net MVC part45 过滤器、模板页
过滤器 使用方式自定义类继承自相应的类或接口,重写方法,作为特性使用在控制器类中重写方法 特性方式的使用注意:如果继承自接口需要让类实现FilterAttribute,才可以作为特性使用使用方式1:作 ...
- .NET反编译
http://www.cnblogs.com/powertoolsteam/archive/2011/01/05/1926066.html
- 【tomcat】FileNotFoundException: C:\Program Files\Java\apache-tomcat-8.5.11-geneshop3\webapps\ROOT\index.html (拒绝访问。)
新装系统后,tomcat启动起来 提示如下错误: Caused by: java.io.FileNotFoundException: C:\Program Files\Java\apache-tomc ...
- 设计工作-Axure
1,百度百科 http://baike.baidu.com/view/3332366.htm?fromtitle=axure&fromid=5056136&type=syn 2,官方网 ...