codeforces 478c Table Decorations

题目链接

C. Table Decorations
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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 rg and b will find the maximum number t of tables, that can be decorated in the required manner.

Input

The single line contains three integers rg 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.

Output

Print a single integer t — the maximum number of tables that can be decorated in the required manner.

Sample test(s)
input
5 4 3
output
4
input
1 1 1
output
1
input
2 3 3
output
2
Note

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。求最多能装扮多少个桌子?

题解:一种较简单的做法,假设r>=g>=b。如果 r>=2*(b+g) ,那么答案是 b+g ,否则,答案是(b+g+r) / 3 。细想一下,只有r>2*(b+g)的时候,剩下的气球才可能超过3个。

我的做法是,先让每张桌子三个气球的颜色一模一样。然后通过贪心地交换桌子间的气球,让尽量多的桌子满足条件。这样最后可能还剩下一些气球,我们再特殊处理就是了。代码如下

#include<stdio.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#define inff 0x3fffffff
#define eps 1e-8
#define nn 510000
#define mod 1000000007
typedef long long LL;
const LL inf64=LL(inff)*inff;
using namespace std;
LL a[4];
LL b[4];
int main()
{
    int i;
    while(cin>>a[1]>>a[2]>>a[3])
    {
        sort(a+1,a+4);
        LL ans=0;
        for(i=1;i<=3;i++)
            b[i]=a[i]%3;
        for(i=1;i<=3;i++)
            a[i]/=3;
        ans+=(a[1]+a[2]);
        LL ix=max(a[3]-a[1]-a[2],LL(0));
        ix-=min(ix,a[1]+a[2]);
        ans+=a[3]-ix;
        LL fc=min(ix,b[1]+b[2]);
        ix-=fc;
        b[3]+=fc;
        ans+=fc;
        LL wy=b[1]+b[2]-fc;
        if(b[3]<3)
        {
            ans+=(b[3]+wy)/3;
        }
        else
        {
            fc=min(b[3]/2,wy);
            ans+=fc;
            b[3]-=fc*2;
            wy-=fc;
            if(b[3]>2)
                b[3]=2;
            ans+=(wy+b[3])/3;
        }
        cout<<ans<<endl;
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值