这是一道找规律的题目
题意是生成一个序列,后一个数是前一个数的两倍,再通过每一位数进行排序生成的新的一个数
一开始想如果出现了5,那么极有可能生成0,使得新的数的位数减少,所以可能存在一个循环节,然后我通过打表出前1000个数,很容易就找到规律
代码:
#include <bits/stdc++.h>
using namespace std;
int a[10], b[1000][10], t, n, m;
const int mo = 2147483600;
int main() {
//freopen("c.out","w",stdout);
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%d", &n);
m = n;
a[1] = 1;
memset(b, 0, sizeof(b));
b[1][1] = 1;
for (int x = 1; x <= 1000; x++) {
/*if (x) {
//for (int i = 0; i < 9; i++) printf("%d,", a[i]);
//printf("%d",a[9]);
for (int i = 1; i <= 9; i++)
for (int j = 1; j <= a[i]; j++) printf("%d", i);
printf("\n");
}*/
t = 0;
for (int i = 9; i >= 1; i--) if (a[i]) {
if (i >= 5) {
b[x+1][(i*2+1)%10] += a[i]-1;
if (t) b[x+1][(i*2+1)%10]++;
else b[x+1][(i*2)%10]++;
} else {
b[x+1][(i*2)%10] += a[i]-1;
if (t) b[x+1][(i*2+1)%10]++;
else b[x+1][(i*2)%10]++;
}
t = (i*2)/10;
}
if (t) b[x+1][1]++;
for (int i = 0; i <= 9; i++) a[i] = b[x+1][i];
}
n = m;
if (n > 1000) n = (n-37)%6+37;
for (int i = 1; i <= 9; i++)
for (int j = 1; j <= b[n][i]; j++) printf("%d", i);
printf("\n");
}