• HDU 1205 吃糖果


    题意:n种糖果, 每种a[i]个, 每次吃一颗,要求连续吃的两颗种类不同,问是否存在一种顺序能吃完所有糖果

    抽屉原理  能否吃完与个数最多的糖果(mx)有关,要吃完mx个至少需要其他种类糖果mx-1个, 设s=a[0]+...+a[n-1]-mx;

    if 其他种类糖果个数不满足要求, 则不能吃完所有糖果

    else s>mx-1,  随着mx--, 次大值会变成mx, 此时一定能保证  (剩下的s) >(当前mx)-1  一直变化 最后就能吃完

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<map>
    #include<queue>
    #include<stack>
    #include<list>
    #include<set>
    using namespace std;
    typedef long long ll;
    typedef pair<ll,ll> p;
    typedef long double ld;
    #define mem(x) memset(x, 0, sizeof(x))
    #define me(x) memset(x, -1, sizeof(x))
    #define fo(i,n) for(i=0; i<n; i++)
    #define sc(x) scanf("%lf", &x)
    #define pr(x) printf("%lld
    ", x)
    #define pri(x) printf("%lld ", x)
    #define lowbit(x) x&-x
    const ll MOD = 1e18 +7;
    const ll N = 6e6 +5;
    ll a[N], vis[N];
    int main()
    {
        ll i, j, k, l=0;
        ll n, m, t, x;
        cin>>t;
        while(t--)
        {
            cin>>n;
            ll mx=-1;
            ll s=0, f=0;
            for(i=0; i<n; i++)
            {
                cin>>a[i];
                s+=a[i];
                mx=max(mx,a[i]);
            }
            s-=mx;
            if(s>=mx-1) f=1;
            if(f) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Spring RESTful Web Services
    Uploadify自定义提示信息
    linux下查找进程及终止进程操作的相关命令
    SecureCRT+SecureFX 7.1.1.264整合版
    关于JSP的语法和常用的内置对象,EL表达式的使用方法
    Servlet的几个常用对象
    使用bootstrap写的简单页面
    bootstrap的使用方法
    EasyUi的使用方法
    Ajax与jQuery的使用方法
  • 原文地址:https://www.cnblogs.com/op-z/p/10751101.html
Copyright © 2020-2023  润新知