1205 吃糖果

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 #include <iostream>
 2 #include <algorithm>
 3 #include <stdio.h>
 4 #include <math.h>
 5 #include <string.h>
 6 #include <time.h>
 7 using namespace std;
 8 int data[1000005];
 9 int main()
10 {
11     long long sum;
12     int n,m,max,i;
13     while(cin>>n)
14     {
15         while(n--)
16         {
17             cin>>m;
18             max=0;
19             sum=0;
20             for(i=0;i<m;i++)
21             {
22                 cin>>data[i];
23                 sum=sum+data[i];
24                 if(max<data[i])
25                 max=data[i];
26             }
27             if(sum%2==0)
28             {
29                 if(max<=sum/2)
30                 cout<<"Yes"<<endl;
31                 else
32                 cout<<"No"<<endl;
33             }
34             else
35             {
36                 if(max<=sum/2+1)
37                 cout<<"Yes"<<endl;
38                 else
39                 cout<<"No"<<endl;
40             }
41         }
42     }
43     return 0;
44 }
View Code

这个题目中4 1 1是指的是每种糖果的数目

posted @ 2016-03-06 22:11  Wally的博客  阅读(172)  评论(0编辑  收藏  举报