Codeforces - 478C. Table Decorations - 思维、贪心

61 篇文章 2 订阅
50 篇文章 0 订阅

Table Decorations

题目链接

分类:思维、贪心

1.题意概述

  • 给你三种颜色的气球Red、Green、Black和他们各自的个数,现在每张桌子要用三个气球装饰,要求同一张桌子的气球颜色不能完全相同,现在问你用这些气球能够最多装饰几张桌子?

2.解题思路

  • 我们不关心具体方案,假设三种颜色气球数量从小到大分别是 a,b,c ,显然如果 c2(a+b) ,剩下的c气球肯定用不着,因此我们实际上取 c =min{2(a+b),c} 即可,因为一张桌子用3个气球,我们贪心地选颜色不同的即可,因此答案就是 a+b+c 3

3.AC代码

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100010
#define lson root << 1
#define rson root << 1 | 1
#define lent (t[root].r - t[root].l + 1)
#define lenl (t[lson].r - t[lson].l + 1)
#define lenr (t[rson].r - t[rson].l + 1)
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
ll a[3];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    long _begin_time = clock();
#endif
    for (int i = 0; i < 3; i++)
        scanf("%I64d", &a[i]);
    sort(a, a + 3);
    a[2] = min((a[1] + a[0] << 1), a[2]);
    printf("%I64d\n", (a[0] + a[1] + a[2]) / 3);
#ifndef ONLINE_JUDGE
    long _end_time = clock();
    printf("time = %ld ms.", _end_time - _begin_time);
#endif
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值