CF 322B Ciel and Flowers 贪心水题

73 篇文章 21 订阅
18 篇文章 0 订阅
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\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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值