zoukankan      html  css  js  c++  java
  • HDU 5665 Lucky (水题)

    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;
    }
    
  • 相关阅读:
    flask多线程多协程操作
    flask介绍
    centos django+Nginx+uwsgi部署
    centos下运行python3.6+Django+mysql项目
    centos虚拟机下安装nginx
    redis安装
    路飞学城课程_课程详细_作业点评
    redis使用方式
    git命令学习
    组合&多态&封装
  • 原文地址:https://www.cnblogs.com/Sunshine-tcf/p/5698897.html
Copyright © 2011-2022 走看看