- 注册时间
- 2008-2-6
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 51573
- 在线时间
- 小时
|
楼主 |
发表于 2011-9-12 20:58:05
|
显示全部楼层
代码-
- #include <stdio.h>
- #include <stdlib.h>
-
- #define M 6
- #define D6 1000000
-
- int D[D6];
- int T[M];
- int N[M];
- int F[M];
- int dT, dN, dF;
- int mask[480];
-
- void init(void)
- {
- int i, j, k, l, m, n;
- for (i = 0; i <= 9; i ++)
- for (j = 0; j <= 9; j ++)
- for (k = 0; k <= 9; k ++)
- for (l = 0; l <= 9; l ++)
- for (m = 0; m <= 9; m ++)
- for (n = 0; n <= 9; n ++)
- D[i*100000+j*10000+k*1000+l*100+m*10+n] = i + j + k + l + m + n;
-
- for (i = 0; i < M; i ++)
- T[i] = N[i] = F[i] = 0;
- F[0] = 1;
- dT = dN = dF = 1;
- for (i = 0; i < 480; i ++)
- mask[i] = 0;
- }
-
- void newT( void )
- {
- int i, t = 0;
- for (i = 0; i < dF; i ++)
- {
- t += T[i] + F[i];
- t >= D6 ? (T[i] = t - D6, t = 1) : (T[i] = t, t = 0);
- }
- i = dF;
- while ((t > 0) && (i < dT))
- {
- t += T[i];
- t >= D6 ? (T[i] = t - D6, t = 1) : (T[i] = t, t = 0);
- i ++;
- }
- if (t > 0)
- T[dT++] = 1;
- }
-
-
- void newN( void )
- {
- int i = 0, t = 6;
- while ((t > 0) && (i < dN))
- {
- t += N[i];
- t >= D6 ? (N[i] = t - D6, t = 1) : (N[i] = t, t = 0);
- i ++;
- }
- if (t > 0)
- N[dN ++] = 1;
- }
-
- void newF( void )
- {
- int i, t = 0;
- for (i = 0; i < dN; i ++)
- {
- t += F[i] + N[i];
- t >= D6 ? (F[i] = t - D6, t = 1) : (F[i] = t, t = 0);
- }
- i = dN;
- while ((t > 0) && (i < dF))
- {
- t += F[i];
- t >= D6 ? (F[i] = t - D6, t = 1) : (F[i] = t, t = 0);
- i ++;
- }
- if (t > 0)
- F[dF++] = 1;
- }
-
- void checkT( void )
- {
- int i, t = 0;
- for (i = 0; i < dT; i ++)
- t += D[T[i]];
- if (mask[t] == 0)
- {
- printf("Find %d: ", t);
- i = dT - 1;
- printf("%d", T[i--]);
- while (i >= 0)
- printf("%06d", T[i--]);
- printf("\n");
- mask[t] = 1;
- }
- }
-
- void checkVar( int * v, int len)
- {
- if (len <= 0)
- return ;
- printf("%d", v[-- len]);
- while ( len > 0)
- printf("%06d", v[-- len]);
- printf("\n");
- }
-
- int main( void )
- {
- long long i = 0;
- init( );
- while ( i <= 100000000 )
- {
- //printf("%d: %d %d %d T, N, F====\n", i, dT, dN, dF);
- //checkVar(T, dT);
- //checkVar(N, dN);
- //checkVar(F, dF);
- newT( );
- newN( );
- newF( );
- checkT( );
- i ++;
- }
- }
复制代码 |
|