UVA - 1583 Digit Generator
//生成元 uva1583 //收获:有时候枚举耗时过多,且对某个数字n,要从0枚举到(n - 1),在这种情况下,最好是建表查表,以提高效率 #include <iostream> #include <cstring> using namespace std; const int maxn = 100005; int a [maxn]; int main() { memset(a, 0, sizeof(a)); for (int i = 1; i < maxn; i++) { int x = i, y = i; while (x) { y += x % 10; x /= 10; } if (!a[y] || i < a[y]) a[y] = i; } int t, n; cin >> t; while (t--) { cin >> n; cout << a[n] << endl; } return 0; }