HDU 5665 Lucky——BestCoder Round #80

Lucky

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


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
BestCoder Round #80
 

/************************************************************************/

附上该题对应的中文题

Lucky

 
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
\ \ \ \    Vampire喜欢玄学,尤其喜欢研究幸运数字.

\ \ \ \    对于一个数字集合S,定义关于S的幸运数字为无法用S中的数相加得到的最小的非负整数(每个数可以使用任意次).

\ \ \ \    现在给定一个数集,如果能使用其中的数相加得到任意自然数,输出”YES”,否则输出”NO”.
输入描述
\ \ \ \    第一行一个正整数T,为数据组数.

\ \ \ \    每组数据第一行一个n,表示集合大小.

\ \ \ \    接下来n个数,表示该数集里的数.

\ \ \ \ 1\le n\le 10^5,1\le T \le 10,0\le a_i \le 10^9    1n105,1T10,0ai109.
输出描述
\ \ \ \    每组数据回答一个”YES”或”NO”.
输入样例
1
1
2
输出样例
NO
/****************************************************/

出题人的解题思路:

1001

因为每个数可以用很多次,所以只要这个集合中有1,那么就可以加出所有的数来.

注意最后要判定一下是否有0.

之前版本的题目描述是用的自然数,后来因为有歧义换成了非负整数.

(本来是打算留个自然数当Trick的..sad story..)

正如出题人所说,集合中只要存在1就必然能够通过一定次数的累加而得到一个正整数,但题目要求是非负整数,所以我们不得不考虑一个特殊数——'0',故此题就转化为求一个集合里是否有0和1的问题
在hack阶段,我看到有人将集合排序,判断集合第一个元素是否为0,集合第二个元素是否为1,但是这种做法很明显没有考虑一个数可能出现多次
好了,话不多说,上代码

/*Sherlock and Watson and Adler*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 100005;
const int M = 1000005;
const int inf = 100000005;
const int mod = 1000000007;
int main()
{
    int t,n,i,x;
    bool flag1,flag2;
    scanf("%d",&t);
    while(t--)
    {
        flag1=flag2=false;
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
            scanf("%d",&x);
            if(!x)
                flag1=true;
            if(x==1)
                flag2=true;
        }
        if(flag1&&flag2)
            puts("YES");
        else
            puts("NO");
    }
    return 0;
}

菜鸟成长记

你可能感兴趣的:(ACM)