首页 > 其他 > 详细

HDU-1205 吃糖果

时间:2014-04-23 15:35:21      阅读:496      评论:0      收藏:0      [点我收藏+]

http://acm.hdu.edu.cn/showproblem.php?pid=1205

  详细解说原理。http://blog.csdn.net/hnust_xiehonghao/article/details/8005832

 鸽巢原理:

2max-sum<=1;

(sum-max+1)>max;

                                吃糖果

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 21940    Accepted Submission(s): 6264


Problem Description
HOHO,终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一种,这样;可是Gardon不知道是否存在一种吃糖果的顺序使得他能把所有糖果都吃完?请你写个程序帮忙计算一下。
 

 

Input
第一行有一个整数T,接下来T组数据,每组数据占2行,第一行是一个整数N(0<N<=1000000),第二行是N个数,表示N种糖果的数目Mi(0<Mi<=1000000)。
 

 

Output
对于每组数据,输出一行,包含一个"Yes"或者"No"。
 

 

Sample Input
2
3
4 1 1
5
5 4 3 2 1
 

 

Sample Output
No
Yes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
     __int64 t,sum,n,x,max,i;
    cin>>t;
    while(t--)
    {   max=sum=0;
        cin>>n;
        for(i=0;i<n;i++)
            {
                cin>>x;
                sum+=x;
                if(max<x)
                   max=x;
            }
            if(2*max-sum<=1)
               cout<<"Yes"<<endl;
             else
              cout<<"No"<<endl;
 
 
    }
    return 0;
}

 

HDU-1205 吃糖果,布布扣,bubuko.com

HDU-1205 吃糖果

原文:http://www.cnblogs.com/cancangood/p/3681666.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!