Heng_Xin 题解分享 · 2024/4/12
卡片(结果填空) - 题解
模拟 ```cpp int main() { vector<int> arr(10, 2021); int i = 1; for (; ; ++i) { int tmp = i; while (tmp) { if (--arr[tmp % 10] < 0) // 不能够拼出 i goto A; tmp /= 10; } } A: cout << i - 1; // 所以 i - 1 return 0; } ```
查看全文
0 0 1 2
desert 题解分享 · 2024/4/7
卡片(结果填空) - 题解
``` #include<bits/stdc++.h> using namespace std; int a[10];//桶的思想,储存0~9卡片的数量 int main() { a[0] = 2020;//因为0不会进入第一次记录,数量减一 for(int i = 1;i <= 9; ++ i)a[i] = 2021;//给0~9的数卡片加上数量 int i = 0,rec = 0,bre = 0;//i为可到达数字,rec为桶中元素的记录,bre为结束状态 //让i不断增加,记录它每个位上的元素,减少桶中对应的卡片数量 while(bre != 1) { cout << i << '\n';//输出i当前值 int j = i;//用j记录i值 while(j > 0)//取出i每一位,从桶中删除卡片次数 { rec = j % 10;//取最后一位 a[rec] --; j = j / 10;//去掉最后一位 } i ++;//可组成的数字增加 //不必要,但是可以查看桶中元素(卡片)当前数量 for(int i = 0;i <= 9; ++ i)cout << a[i] << ' '; cout << '\n'; //一旦桶中有卡片数量不够,激活终止标记 for(int j = 0;j <= 9; ++ j){//判断桶中是否有空元素 if(a[j] <= 0){ bre = 1;//终止标记状态变化 } } } return 0; } ```
查看全文
0 0 1 3
Fxzbed 题解分享 · 2024/4/4
卡片(结果填空) - 题解
``` #include <iostream> using namespace std; int a[10], res; int main(void) { while (++res) { auto t = res; while (t) { int bit = t % 10; a[bit] ++; if (a[bit] == 2022) { cout << res - 1; return 0; } t /= 10; } } } ```
查看全文
0 0 1 2
acmer10 题解分享 · 2024/4/3
卡片(结果填空) - 题解
``` #include<iostream> #include<cstring> #include<algorithm> #include<math.h> using namespace std; int used,cnt; //1 用到2021 张 就是极限 //i表示卡片拼成的数 int main() { for(int i=1;;i++) { int tmp=i; while(tmp) { if(tmp%10==1)used++; if(used==2021) { cout<<i<<endl; return 0; } tmp/=10; } } return 0; } ```
查看全文
0 0 1 0
WonderfulD 题解分享 · 2024/4/4
卡片(结果填空) - 题解
```java public static void main(String[] args) throws IOException { Map<String, Integer> map = new HashMap<>(); for (int i = 0; i < 10; i++) { map.put(i + "", 2021); } int num = 1; while(true) { String s = num + ""; String[] s1 = s.split(""); for (String s2 : s1) { if (map.get(s2) == 0) { System.out.println(num - 1); return; }else { map.put(s2, map.get(s2) - 1); } } num += 1; } } ```
查看全文
0 0 0 7
Dervish 题解分享 · 2024/4/7
卡片(结果填空) - 题解
``` #include #include <cstring> #include <algorithm> using namespace std; int main() { int a[10] = {2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021}; int res = 0, i = 1; while(true) { bool flag = true; int temp = i; while(temp) { if(a[temp%10] == 0) { flag = false; break; } a[temp % 10]--; temp /= 10; } if(flag) { res++; i++; } else { break; } } cout << res; return 0; } ``` ``` ```
查看全文
0 0 0 3
sakura1 题解分享 · 2024/4/20
卡片(结果填空) - 题解
``` public class Main { public static void main(String[] args) { // 用一个数组存这0-9的数字,每个数字都有2021张 int[] arr = new int[] { 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021 }; int ans = 0;// 每一次拼好的数字 // 模拟拼数字 for (int i = 1;; i++) { int k = i; while (k != 0) { //如果数组中这个数字用完了,就结束输出ans if (arr[k % 10] == 0) { System.out.println(ans); return; } //没用完则让这个数字的张数-1 arr[k % 10]--; k /= 10; } ans++; } } } ```
查看全文
0 0 0 2
starry 题解分享 · 2024/4/8
卡片(结果填空) - 题解
纯暴力解法 ``` a0,a1,a2,a3,a4,a5,a6,a7,a8,a9=2021,2021,2021,2021,2021,2021,2021,2021,2021,2021 for i in range(1,999999999999999999): s=str(i) a0 -= s.count('0') a1 -= s.count('1') a2 -= s.count('2') a3 -= s.count('3') a4 -= s.count('4') a5 -= s.count('5') a6 -= s.count('6') a7 -= s.count('7') a8 -= s.count('8') a9 -= s.count('9') if a0<0 or a1<0 or a2<0 or a3<0 or a4<0 or a5<0 or a6<0 or a7<0 or a8<0 or a9<0: print(i-1) break ```
查看全文
0 0 0 2
undefine 题解分享 · 2024/4/8
卡片(结果填空) - 题解
Python暴力代码 ``` card=[2021]*10 i=1 m=0 while not card.count(0): for j in str(i): card[int(j)]-=1 if card[int(j)]<0: break else: m+=1 i+=1 print(m) ```
0 0 0 2
Minus 题解分享 · 2024/4/8
卡片(结果填空) - 题解
``` #include<iostream> using namespace std; int main() { int a[10] = {2021,2021,2021,2021,2021,2021,2021,2021,2021,2021}; int num = 1; bool flag = true ; while(flag) { string b = to_string(num++); for(int i = 0 ; i <= b.size()-1 ; i++) { a[b[i] - '0'] --; } for(int i = 0 ; i <= 9 ; i++ ) { if(!a[i]) { flag = false ; } } } cout<<num - 1<<endl; return 0; } ```
查看全文
0 0 0 2