hdu 1205 吃糖果 输入挂+抽屉原理

有最多数量的某种糖果数量为maxn,接下来问题转化成能否将在maxn个相同的糖果序列中间差入一些其他糖果,将相同的糖果分开。根据抽屉原理,最少需要maxn-1个糖果。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long ll;

inline int read()
{
    char ch=getchar();int x=0,f=1;
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int main()
{
    int _,t,n,i,maxn;
    ll sum;
    scanf("%d",&_);
    while(_--)
    {
        scanf("%d",&n);
        sum=maxn=0;
        for(i=0;i<n;i++)
        {
            t=read();
            maxn=max(t,maxn);
            sum+=t;
        }
        if(sum-maxn+1>=maxn) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

posted @ 2015-08-24 11:30  xryz  阅读(129)  评论(0编辑  收藏  举报