solution1
直接依次计算,思维上最直接
cpp
#include<stdio.h>
int main(){
int a[10], n = 1, t1, t2, flag = 1;
for(int i = 0; i < 10; i++)
a[i] = 2021;
while(flag){
t1 = n;
while(t1){
t2 = t1 % 10;
a[t2]--;
if(a[t2] < 0){
flag = 0;
break;
}
t1 /= 10;
}
if(!t1 && flag) n++;
}
printf("%d", n - 1);
return 0;
}
solution2
观察可知,点数最小的卡片1最先消耗完
==》问题转化为1什么时候用光
cpp
#include<stdio.h>
int main(){
int n = 1, t1, t2, flag = 1, one = 0;
while(flag){
t1 = n;
while(t1){
t2 = t1 % 10;
if(t2 == 1) one++;
if(one == 2021){
flag = 0;
break;
}
t1 /= 10;
}
if(!t1 && flag) n++;
}
printf("%d", n);
return 0;
}