Lucky

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 138    Accepted Submission(s): 96


Problem Description
     Chaos August likes to study the lucky numbers.

     For a set of numbers S,we set the minimum non-negative integer,which can't be gotten by adding the number in S,as the lucky number.Of course,each number can be used many times.

     Now, given a set of number S, you should answer whether S has a lucky number."NO" should be outputted only when it does have a lucky number.Otherwise,output "YES".
 

 

Input
     The first line is a number T,which is case number.

     In each case,the first line is a number n,which is the size of the number set.

     Next are n numbers,means the number in the number set.

    1n105,1T10,0ai109 .
 

 

Output
     Output“YES”or “NO”to every query.
 

 

Sample Input
1
1
2
 

 

Sample Output
NO
 

 

Source
 
题意:集合S 中 有若干数 如果能够通过任意 组合(不限次数)加和得到所有 自然数 则输出“YES” 否则“NO”
 
 
题解:自然数包含0 
        判断可以发现 只有当S中存在 “0”与“1”时才会满足条件输出“YES”
 
 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<queue>
 5 #include<stack>
 6 #define ll __int64
 7 #define pi acos(-1.0)
 8 using namespace std;
 9 int t;
10 int n;
11 ll a;
12 int main()
13 {
14     scanf("%d",&t);
15     for(int i=1;i<=t;i++)
16     {
17         scanf("%d",&n);
18         int flag1=0;
19         int flag2=0;
20         for(int j=1;j<=n;j++)
21         {
22             scanf("%I64d",&a);
23             if(a==1)
24             {
25             flag1=1;
26             }
27             if(a==0)
28             {
29             flag2=1;
30             }
31         }
32         if(flag1==1&&flag2==1)
33          cout<<"YES"<<endl;
34          else
35          cout<<"NO"<<endl;
36     }
37     
38     return 0;
39 }