hdu-5665 Lucky(水题)
题目链接:
Lucky
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
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".
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.
1≤n≤10^5,1≤T≤10,0≤ai≤10^9.
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.
1≤n≤10^5,1≤T≤10,0≤ai≤10^9.
Output
Output“YES”or “NO”to every query.
Sample Input
1
1
2
Sample Output
NO
题意:
问给的这个集合,能否用这个集合的数相加得到任意的自然数,每个数可以用无数遍;
思路:
只要有0和1就可以得到所有的自然数;
AC代码:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath> using namespace std; typedef long long ll; const ll mod=1e9+7; const int N=1e5+10; int n,a[N]; int main() { int t; scanf("%d",&t); while(t--) { scanf("%d",&n); int flag1=0,flag2=0; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); if(a[i]==1)flag1=1; if(a[i]==0)flag2=1; } if(flag1&&flag2)printf("YES\n"); else printf("NO\n"); } return 0; }