HDU 1205 吃糖果

题意:

(中文)

思路:

刚开始拿到这道题是在杭电的ACM课件上的,没想到强校的课堂思考都这么有深度。

用到了鸽巢原理。。。。

1.咱们可以把一种的每个糖果当成一个隔板(有n个),这样用另一种糖果来填这些空,正好把这些糖果”分开“的最小数目是n - 1个。

2.如果另一种糖果多于n - 1个,那么我们可以用多出来的这些糖果“加厚”隔板(也算分割)。

那么就是考虑最多的那种糖果,把这种糖果当成最开始的隔板,然后把其它种类的糖果来进行”分开“和”加厚“操作, 这样允许的方程是:

sum - maxn >= maxn - 1;

Code:

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<bitset>
#include<set>
#include<map>
#include<cctype>
#include<vector>

#define TEST

#define LL long long
#define Mt(f, x) memset(f, x, sizeof(f));
#define xep(i, n) for(int i = 0; i < (n); ++i)
#define rep(i, s, e) for(int i = (s); i <= (e); ++i)
#define dep(i, s, e) for(int i = (s); i >= (e); --i)
#ifdef TEST
    #define See(a) cout << #a << " = " << a << endl;
    #define See2(a, b) cout << #a << " = " << a << ' ' << #b << " = " << b << endl;
    #define debug(a, s, e){ rep(_i, s, e) {cout << a[_i] << ' '; }cout << endl;}
    #define debug2(a, s, e, ss, ee) rep(i_, s, e) {debug(a[i_], ss, ee);}
#else
    #define See(a) {}
    #define See2(a, b) {}
    #define debug(a, s, e) {}
    #define debug2(a, s, e, ss, ee) {}
#endif

const int MAX = 2e9;
const int MIN = -2e9;
const double PI = acos(-1.0);
const double eps = 1e-9;

using namespace std;

int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        int n;
        scanf("%d", &n);
        LL sum = 0;
        int maxn = MIN, a;
        xep(i, n)
        {
            scanf("%d", &a);
            sum += a;
            maxn = max(maxn, a);
        }
        if(sum - maxn + 1 >= maxn)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值