www.MyException.Cn  网友分享于：2013-03-30  浏览：13次

faint..

90 : [?][?] ==> 十位为1， 10种情况。 各位为1， 9种情况。 所以是 19个结果。。
800 : [?][?][?] ==> 10 * 10 + 10 * 8 + 10 * 8 = 260.
7000 : ===> 10 * 10 * 10 + 10 * 10 * 7 + 10 * 10 * 7 + 10 * 10 * 7 = 3100

===================================================

9, 99,999,9999,...
0,10,100,1000,10000....

2,3000,4000,500....

================================================

f(n,m) = 10^m + m*7*10^(m-1)
================================================真理啊。。。

------解决方案--------------------

（1）求当前值加1后的BCD码(8421)的值。
（2）求当前累加值BCD码中1的个数。
（3）将当前值中1的个数与之前1的个数进行求和。
（4）检查当前n值与累计1的值是否相同，相同则输出n。

#include "stdafx.h "
#include <windows.h>

int inc1_arr[65536] = {
0X000001,0X000002,0X000003,0X000004,0X000005,0X000006,0X000007,0X000008,0X000009,0X000010,
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0X000011,0X000012,0X000013,0X000014,
0X000015,0X000016,0X000017,0X000018,0X000019,0X000020,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,
......//数量较多省略(其中下标为0x9999的值为0x010000，值为0xFFFFFF表示BCD码无效)
};

char count1_arr[65536] = {
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
......//数量较多省略
};

int main(int argc, char* argv[])
{
unsigned short usBCD[3] = {0, 0, 0};
int i, k;
int iSum = 0;

DWORD dwTick = GetTickCount();

for(i = 1; i <= 1234567890; i ++) {
k = inc1_arr[usBCD[0]];
usBCD[0] = k & 0xffff;
if(k & 0x00ff0000) {
k = inc1_arr[usBCD[1]];
usBCD[1] = k & 0xffff;
if(k & 0x00ff0000) {
k = inc1_arr[usBCD[2]];
usBCD[2] = k & 0xffff;
}
}
iSum += count1_arr[usBCD[0]] + count1_arr[usBCD[1]] + count1_arr[usBCD[2]];
if(iSum == i) {
printf( "%d\n ", i);
}
}

printf( "\nTime Used: %d mSec\n ", GetTickCount() - dwTick);

return 0;
}

VC++ 6.0下编译通过，在Pentium M 1.4GHz笔记本上的运行结果(不到20秒)：
1
199981
199982
199983
199984
199985
199986
199987
199988
199989
199990
200000
200001
1599981
1599982
1599983
1599984
1599985
1599986
1599987
1599988
1599989
1599990
2600000
2600001
13199998
35000000
35000001
35199981
35199982
35199983
35199984
35199985
35199986
35199987
35199988
35199989
35199990
35200000
35200001
117463825
500000000
500000001
500199981
500199982
500199983
500199984
500199985
500199986
500199987
500199988
500199989
500199990
500200000
500200001
501599981
501599982
501599983
501599984
501599985
501599986