E - Problem E ( 吃糖) :HDU - 1205

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


       
解题思路:只要sum-MAX >= MAX - 1就可以了

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int N;
 8     cin>>N;
 9     while(N--)
10     {
11       double sum = 0;
12        double Max = 0;
13         double n;
14         cin>>n;
15         for(int i = 1;i<=n;i++)
16         {
17             double temp ;
18             cin>>temp;
19             sum+=temp;
20             Max = Max > temp? Max:temp;
21         }
22 
23         if(sum - Max >= Max - 1)
24             cout<<"Yes"<<endl;
25         else
26             cout<<"No"<<endl;
27 
28 
29     }
30 
31     return 0;
32 }

 

posted @ 2017-08-05 09:25  山杉三  阅读(128)  评论(0编辑  收藏  举报