zoukankan      html  css  js  c++  java
  • codeforce 1478B B. Nezzar and Lucky Number 找规律 打表 C

    codeforce 1478B B. Nezzar and Lucky Number 找规律 打表 C

    https://codeforces.com/contest/1478/problem/B

    B. Nezzar and Lucky Number
    time limit per test
    1 second
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    Nezzar's favorite digit among 1,,91,…,9 is dd. He calls a positive integer lucky if dd occurs at least once in its decimal representation.

    Given qq integers a1,a2,,aqa1,a2,…,aq, for each 1iq1≤i≤q Nezzar would like to know if aiai can be equal to a sum of several (one or more) lucky numbers.

    Input

    The first line contains a single integer tt (1t91≤t≤9) — the number of test cases.

    The first line of each test case contains two integers qq and dd (1q1041≤q≤104, 1d91≤d≤9).

    The second line of each test case contains qq integers a1,a2,,aqa1,a2,…,aq (1ai1091≤ai≤109).

    Output

    For each integer in each test case, print "YES" in a single line if aiai can be equal to a sum of lucky numbers. Otherwise, print "NO".

    You can print letters in any case (upper or lower).

    Example
    input
    Copy
    2
    3 7
    24 25 27
    10 7
    51 52 53 54 55 56 57 58 59 60
    
    output
    Copy
    YES
    NO
    YES
    YES
    YES
    NO
    YES
    YES
    YES
    YES
    YES
    YES
    NO
    
    Note

    In the first test case, 24=17+724=17+7, 2727 itself is a lucky number, 2525 cannot be equal to a sum of lucky numbers.

    分析

    题目需要判断一个数能否由几个幸运数组成,但a数组的范围是1e9

    猜测大数据直接被屏蔽,可以得到d*10之后就都可以任意表示,因为10可以任意使用,个位也可以任意使用

    小数据直接疯狂暴力即可

    比赛的时候因为数组范围又疯狂wa了两次

    代码

    https://codeforces.com/contest/1478/problem/B

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    #include <math.h>
    #include <string.h>
    #include <algorithm>
    #include <iostream>
    #include <string>
    #include <sstream>
    #include <iostream>
    #include <time.h>
    #include <queue>
    #include <list>
    #include <map>
    #include <set>
    #include <vector>
    #include <stack>
    #include <string.h>
    #include <bitset>
    #define sf scanf
    #define pf printf
    #define lf double
    #define p123 printf("123
    ");
    #define pn printf("
    ");
    #define pk printf(" ");
    #define p(n) printf("%d",n);
    #define pln(n) printf("%d
    ",n);
    #define s(n) scanf("%d",&n);
    #define ss(n) scanf("%s",n);
    #define ps(n) printf("%s",n);
    #define sld(n) scanf("%lld",&n);
    #define pld(n) printf("%lld",n);
    #define slf(n) scanf("%lf",&n);
    #define plf(n) printf("%lf",n);
    #define sc(n) scanf("%c",&n);
    #define pc(n) printf("%c",n);
    #define gc getchar();
    #define ll long long
    #define re(n,a) memset(n,a,sizeof(n));
    #define len(a) strlen(a)
    #define eps 1e-13
    #define zero(x) (((x) > 0? (x):(-x)) < eps)
    using namespace std;
    
    int temp[15][20000];
    int main(){
        int t;
        s(t)
        re(temp,0);
        for(int i = 1; i<= 10000; i ++){
            temp[1][i] = 1;
        }
        for(int i = 2; i <= 9; i ++){
            for(int j = 1; j <= 30; j ++){
                for(int k = 0; k <= 30; k ++){
                    temp[i][i*j+k*10] = 1;
                }
            }
        }
        while(t --){
            int n,d;
            s(n) s(d)
            int x;
            for(int i = 0; i < n; i ++){
                s(x)
                if(x >= d*10){
                    puts("YES");
                }else if(temp[d][x] == 1){
                    puts("YES");
                }else{
                    puts("NO");
                }
    
            }
    
    
        }
        return 0;
    }
    作者:kidgzz
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    JVM视角:值传递or引用传递?【转】
    mybaits trim用法
    Collections.shuffle()用法
    api缓存
    接口开发
    Integer.parseInt()和这个Integer.valueOf()的详解【转】
    MyBatis 通过包含的jdbcType类型
    idea 相关设置
    idea快捷键
    equals 与 ==
  • 原文地址:https://www.cnblogs.com/Kidgzz/p/14347326.html
Copyright © 2011-2022 走看看