codeforce 1478B B. Nezzar and Lucky Number 找规律 打表 C
https://codeforces.com/contest/1478/problem/B
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 1≤i≤q1≤i≤q Nezzar would like to know if aiai can be equal to a sum of several (one or more) lucky numbers.
The first line contains a single integer tt (1≤t≤91≤t≤9) — the number of test cases.
The first line of each test case contains two integers qq and dd (1≤q≤1041≤q≤104, 1≤d≤91≤d≤9).
The second line of each test case contains qq integers a1,a2,…,aqa1,a2,…,aq (1≤ai≤1091≤ai≤109).
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).
2 3 7 24 25 27 10 7 51 52 53 54 55 56 57 58 59 60
YES NO YES YES YES NO YES YES YES YES YES YES NO
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; }