您的位置:首页 > 其它

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

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

[code]#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: