AtCoder Beginner Contest 161 比赛人数9927 快,比赛开始后5分钟看到所有题
AtCoder Beginner Contest 161 D Lunlun Number 打表+找规律+构造
总目录详见https://blog.csdn.net/mrcrack/article/details/104454762
在线测评地址https://atcoder.jp/contests/abc161/tasks/abc161_d
此类问题,手工模拟,对应的是成千上万的数据,还是打表,不容易模拟数据出错。
打表代码如下
#include
#include
#define LL long long
using namespace std;
int a[15];
int judge(LL x){
int i,top=0;
while(x){
a[++top]=x%10;
x/=10;
}
for(i=2;i<=top;i++)
if(abs(a[i]-a[i-1])>1)return 0;
return 1;
}
int main(){
int cnt=0;
LL i,n;
scanf("%lld",&n);
for(i=1;i<=n;i++)
if(judge(i))cnt++,printf("%lld,",i);
printf("\ncnt=%d\n",cnt);
return 0;
}
将打表代码编译,运行,输入9999,得到如下输出数据
1,2,3,4,5,6,7,8,9,
10,11,12,
21,22,23,
32,33,34,
43,44,45,
54,55,56,
65,66,67,
76,77,78,
87,88,89,
98,99,
100,101,
110,111,112,
121,122,123,
210,211,212,
221,222,223,
232,233,234,
321,322,323,
332,333,334,
343,344,345,
432,433,434,
443,444,445,
454,455,456,
543,544,545,
554,555,556,
565,566,567,
654,655,656,
665,666,667,
676,677,678,
765,766,767,
776,777,778,
787,788,789,
876,877,878,
887,888,889,
898,899,
987,988,989,
998,999,
1000,1001,
1010,1011,1012,
1100,1101,
1110,1111,1112,
1121,1122,1123,
1210,1211,1212,
1221,1222,1223,
1232,1233,1234,
2100,2101,
2110,2111,2112,
2121,2122,2123,
2210,2211,2212,
2221,2222,2223,
2232,2233,2234,
2321,2322,2323,
2332,2333,2334,
2343,2344,2345,
3210,3211,3212,
3221,3222,3223,
3232,3233,3234,
3321,3322,3323,
3332,3333,3334,
3343,3344,3345,
3432,3433,3434,
3443,3444,3445,
3454,3455,3456,
4321,4322,4323,
4332,4333,4334,
4343,4344,4345,
4432,4433,4434,
4443,4444,4445,
4454,4455,4456,
4543,4544,4545,
4554,4555,4556,
4565,4566,4567,
5432,5433,5434,
5443,5444,5445,
5454,5455,5456,
5543,5544,5545,
5554,5555,5556,
5565,5566,5567,
5654,5655,5656,
5665,5666,5667,
5676,5677,5678,
6543,6544,6545,
6554,6555,6556,
6565,6566,6567,
6654,6655,6656,
6665,6666,6667,
6676,6677,6678,
6765,6766,6767,
6776,6777,6778,
6787,6788,6789,
7654,7655,7656,
7665,7666,7667,
7676,7677,7678,
7765,7766,7767,
7776,7777,7778,
7787,7788,7789,
7876,7877,7878,
7887,7888,7889,
7898,7899,
8765,8766,8767,
8776,8777,8778,
8787,8788,8789,
8876,8877,8878,
8887,8888,8889,
8898,8899,
8987,8988,8989,
8998,8999,
9876,9877,9878,
9887,9888,9889,
9898,9899,
9987,9988,9989,
9998,9999,
cnt=327
挑出特殊数据进行研究
98,99,
100,101,
898,899,
998,999,
1000,1001,
1100,1101,
2100,2101,
7898,7899,
8898,8899,
8998,8999,
9898,9899,
9998,9999,
以8,9,10为例展示数据生成过程
8生成的2位数有87,88,89
9生成的2位数有98,99
10生成的2位数有100,101
其它数据生成过程,不外乎上述三种过程。
熟知数据生成过程后,构造出符合题意的100000组数据,待测试数据挑选。
AC代码如下
#include
#define maxn 100010
#define LL long long
LL rd[maxn]={1,2,3,4,5,6,7,8,9};
int main(){
int i,id,k;
scanf("%d",&k);
i=9,id=0;
while(i