//生成元 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;
}
UVA - 1583 Digit Generator
程序员文章站
2024-02-25 08:19:52
...
上一篇: 公共POI导出Excel方法详解
推荐阅读
-
UVA - 1583 Digit Generator
-
UVa 1583 - Digit Generator
-
UVa 1583 - Digit Generator
-
UVa 1583 - Digit Generator
-
uva 1583 Digit Generator
-
UVa 1583 - Digit Generator
-
Digit Generator UVA – 1583
-
UVA 1225 Digit Counting(c++)(模拟)
-
[Digit Generator, ACM/ICPC Seoul 2005, UVA1583]
-
Specialized Four-Digit Numbers POJ 2196 ZOJ 2405 UVA 3199