CF 322B Ciel and Flowers 贪心水题

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 rg 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
",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
",ans);
    }
    return 0;
}



原文地址:https://www.cnblogs.com/jiangu66/p/3186968.html