CF 322B Ciel and Flowers 贪心水题
1 second
256 megabytes
standard input
standard output
Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers.
- To make a "green bouquet", it needs 3 green flowers.
- To make a "blue bouquet", it needs 3 blue flowers.
- To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower.
Help Fox Ciel to find the maximal number of bouquets she can make.
The first line contains three integers r, g and b (0 ≤ r, g, b ≤ 109) — the number of red, green and blue flowers.
Print the maximal number of bouquets Fox Ciel can make.
3 6 9
6
4 4 4
4
0 0 0
0
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
题目意思是
做蓝的花束需要3朵蓝花,做红的花束需要3朵红花,绿的花束需要3朵绿花,混合花束需要3种颜色各一朵
现在给出红,绿,蓝花的数目,问最多有几个花束可以做出来。
贪心。对r,g,b分别除3取余数,为r1,g1,b1时,
然后排序一下,如果 r1==0 , g1 == 2, b1 == 2时,且原始的r答案再加1。减少一个r花的数目,换得2个混合花
/*
* @author ipqhjjybj
* @date 20130711
*
*/
#include <cstdio>
#include <cstdlib>
#include <algorithm>
void swap(int &a,int &b){
int t;
t=a,a=b,b=t;
}
int main(){
int r,g,b,ans=0;
scanf("%d %d %d",&r,&g,&b);
if(r==0||g==0||b==0){
printf("%d\n",r/3+b/3+g/3);
}else{
ans = r/3+g/3+b/3;
r%=3,g%=3,b%=3;
if(r>=g) swap(r,g);
if(r>=b) swap(r,b);
if(g>=b) swap(g,b);
// r<=g<=b
if(r==0&&g==2){
ans+=1;
}else{
ans+=r;
}
printf("%d\n",ans);
}
return 0;
}
CF 322B Ciel and Flowers 贪心水题的更多相关文章
- PAT甲题题解-1125. Chain the Ropes (25)-贪心水题
贪心水题,每次取最短的两个绳子合并,长度缩减成一半 #include <iostream> #include <cstdio> #include <algorithm&g ...
- 【贪心算法】POJ-2393 简单贪心水题
一.题目 Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over ...
- UVA 11389 The Bus Driver Problem 贪心水题
题目链接:UVA - 11389 题意描述:有n个司机,n个早班路线和n个晚班路线,给每个司机安排一个早班路线和一个晚班路线,使得每个早班路线和晚班路线只属于一个司机.如果一个司机早班和晚班总的驾驶时 ...
- cogs 1440. [NOIP2013]积木大赛 贪心水题
1440. [NOIP2013]积木大赛 ★★ 输入文件:BlockNOIP2013.in 输出文件:BlockNOIP2013.out 简单对比时间限制:1 s 内存限制:128 M ...
- UVa(11292),贪心水题
蓝书P1, 很简单的一个贪心选择,用能力小的去砍小的.本来想双重循环,哎,傻逼了,直接遍历选手,碰到能砍的就砍掉. #include <stdio.h> #include <algo ...
- codeforces 672C - Recycling Bottles 贪心水题
感觉很简单,就是讨论一下 #include <stdio.h> #include <string.h> #include <algorithm> #include ...
- 贪心水题。UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing
UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { ; ){ ; ) r ...
- Codeforces Round #493 (Div. 2) A. Balloons 贪心水题
由于是输出任意一组解,可以将价值从小到大进行排序,第一个人只选第一个,第二个人选其余的.再比较一下第一个人选的元素和第二个人所选元素和是否相等即可.由于已将所有元素价值从小到大排过序,这样可以保证在有 ...
- hdu_2124 Flying to the Mars & hdu_1800 Repair the Wall 贪心水题
hdu_1800 简单排一下序,从大开始把比他小的都访问一遍,ans++: #include <iostream> #include <stdio.h> #include &l ...
随机推荐
- XAMPP on Mac 组态 Virual Host
首先,在hosts文件中添加virtual host域名.方向127.0.0.1 我一般使用的命名约定dev-domainname.com sudo nano /private/etc/hosts # ...
- :link,:visited,:focus,:hover,:active详解
原文::link,:visited,:focus,:hover,:active详解 CSS 又名 层叠样式表,所谓层叠,就是后面的样式会覆盖前面的样式,所以在样式表中,各样式排列的顺序很有讲究. ...
- Android单元测试Junit (一)
1.在eclips中建立一个Android工程,具体信息如下: 2.配置单元测试环境,打开AndroidManifest.xml,具体代码如下所示: <?xml version="1. ...
- 网易ios 面试
1 说说 你对 MRC和 ARC 的理解 2 对OC内存分析 有什么好的方法, 3 corePlot 4 pop 动画 5 cocoapods 6 GCD 7 瀑布流 及 uicollection ...
- 【转】android webview设置内容的字体大小
Enum for specifying the text size. SMALLEST is 50% SMALLER is 75% NORMAL is 100% LARGER is 150% LARG ...
- Nhibernate分页测试续
Nhibernate分页测试续(附源码) 接着上一篇Nhibernate分页测试,最近一直在接触Nhibernate,接触的越多.了解越深,越是感觉他的强大,很多功能都封装的很好,对数据操作是那么的简 ...
- ofbiz学习笔记01--多表关联查询
不管做什么项目,肯定会用到多表关联查询数据,从网络查询得知ofbiz有三种多表关联查询方法 实现一:Screem.xml 中的 section 里,加 <action>, 加 get-re ...
- Yeoman入门之安装及环境配置
Yeoman入门之安装及环境配置 http://blog.csdn.net/panlingfan/article/details/27345037 http://www.nodejs.orgYEOMA ...
- [推荐分享]大量Javascript/JQuery学习教程电子书合集,送给有需要的人
不收藏是你的错^_^. 经证实,均可免费下载. 资源名称 资源大小 15天学会jQuery(完整版).pdf 274.79 KB 21天学通JavaScript(第2版)-顾宁燕扫描版.pdf ...
- bootstrap + angularjs + seajs构建Web Form前端(1)
bootstrap + angularjs + seajs构建Web Form前端(一) 简介 Bootstrap是Twitter推出的一个用于前端开发的开源工具包,它由Twitter的设计师Mark ...