zoukankan      html  css  js  c++  java
  • HDU 5665

    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 } 
     
  • 相关阅读:
    P1410 子序列 (动态规划)
    P2085 最小函数值 (堆)
    [ZJOI2007]棋盘制作 (单调栈,动态规划)
    [ZJOI2005]午餐 (贪心,动态规划)
    黑匣子_NOI导刊2010提高 (对顶堆)
    [BZOJ1455] 罗马游戏 (左偏树||并查集)
    P1651 塔 (动态规划)
    两类斯特林数 (组合数学)
    从编程到工程
    失败的过程也是过程
  • 原文地址:https://www.cnblogs.com/hsd-/p/5399811.html
Copyright © 2011-2022 走看看