Lucky
题目链接:
http://acm.hust.edu.cn/vjudge/contest/123316#problem/G
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.
.
Output
Output“YES”or “NO”to every query.
Sample Input
1
1
2
Sample Output
No
题意:
给出一个具有n个数字的集合;
定义lucky number:不能由集合中的数字相加得到的最小的数.
题解:
能否构成任意正数取决于是否含有1,有1则一定能,否则一定不能.
注意题目说的是非负整数,则还要考虑0; 只有当含有0的时候才能得到0.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#define LL long long
#define eps 1e-8
#define maxn 1100
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;
int n;
int main(int argc, char const *argv[])
{
//IN;
int t; scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
int flag = 0;
int flag2 = 0;
for(int i=1; i<=n; i++) {
int x; scanf("%d", &x);
if(x == 1) flag = 1;
if(x == 0) flag2 = 1;
}
if(flag && flag2) printf("YES
");
else printf("NO
");
}
return 0;
}