您的位置:首页 > 其它

HDU 5665

2016-04-16 23:31 447 查看

Lucky

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


[align=left]Problem Description[/align]

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".

[align=left]Input[/align]

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≤105,1≤T≤10,0≤ai≤109

.

[align=left]Output[/align]

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

[align=left]Sample Input[/align]

1
1

2

[align=left]Sample Output[/align]

NO

[align=left]Source[/align]
BestCoder Round #80

题意:集合S 中 有若干数 如果能够通过任意 组合(不限次数)加和得到所有 自然数 则输出“YES” 否则“NO”

题解:自然数包含0
判断可以发现 只有当S中存在 “0”与“1”时才会满足条件输出“YES”

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#define ll __int64
#define pi acos(-1.0)
using namespace std;
int t;
int n;
ll a;
int main()
{
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
scanf("%d",&n);
int flag1=0;
int flag2=0;
for(int j=1;j<=n;j++)
{
scanf("%I64d",&a);
if(a==1)
{
flag1=1;
}
if(a==0)
{
flag2=1;
}
}
if(flag1==1&&flag2==1)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: