记录编号 576944 评测结果 AAAAAAAAAA
题目名称 [USACO Open09] 数字的游戏 最终得分 100
用户昵称 GravatarHeSn 是否通过 通过
代码语言 C++ 运行时间 0.932 s
提交时间 2022-10-19 09:38:16 内存使用 13.37 MiB
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1000010;
int f[MAXN];
signed main() {
	freopen("cdgame.in", "r", stdin);
	freopen("cdgame.out", "w", stdout);
	memset(f, -0x3f, sizeof(f));
	for(int i = 1; i < 10; i ++) {
		f[i] = 1;
	}
	for(int i = 10; i <= MAXN; i ++) {
		int x = i, maxn = 0, minn = 100;
		while(x) {
			int w = x % 10;
			maxn = max(maxn, w);
			if(w != 0) {
				minn = min(minn, w);
			}
			x /= 10;
		}
		if(!minn) {
			minn = maxn;
		}
		if(f[i - maxn] < 0 || f[i - minn] < 0) {
			f[i] = 1;
		}
//		cout << i << ' ' << maxn << ' ' << minn << ' ' << f[i] << endl;
	}
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++) {
		int x;
		cin >> x;
		if(f[x] == 1) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}