CF 322B Ciel and Flowers 贪心水题
2013-07-12 19:01
309 查看
B. Ciel and Flowers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.
Input
The first line contains three integers r, g and b (0 ≤ r, g, b ≤ 109) — the number of red, green and blue flowers.
Output
Print the maximal number of bouquets Fox Ciel can make.
Sample test(s)
input
output
input
output
input
output
Note
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个混合花
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.
Input
The first line contains three integers r, g and b (0 ≤ r, g, b ≤ 109) — the number of red, green and blue flowers.
Output
Print the maximal number of bouquets Fox Ciel can make.
Sample test(s)
input
3 6 9
output
6
input
4 4 4
output
4
input
0 0 0
output
0
Note
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 782C 贪心,DFS染色,水题
- CF 322B Ciel and Flowers 贪心水题
- CF 557B(Pasha and Tea-贪心)
- hdu 1009 FatMouse' Trade(贪心水题)
- hdu 4296 贪心水题 轮换不等式;
- poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)
- CF-Pasha and Tea(贪心6)
- 水题(Maxim and Array,cf 721D)
- CF - 808E. Selling Souvenirs - 01背包dp+排序+贪心/三分优化
- DP+贪心水题合集_C++
- 贪心,优化(Sockets,cf 732e)
- “师创杯”山东理工大学第九届ACM程序设计竞赛 正式赛 G.打字【Dp+贪心】水题
- Given Length and Sum of Digits...---------cf水题
- hdu1257最少拦截系统---贪心水题
- CF 500 C. New Year Book Reading 贪心 简单题
- CF_605A(水题)
- 【打CF,学算法——一星级】CodeForces 227B Effective Approach (水题)
- cf水题:231A - Team
- CF - 472C. Design Tutorial: Make It Nondeterministic 贪心+字符串+模拟
- HDOJ1009 贪心水题