1550: [蓝桥杯2021初赛] 卡片
内存限制:256 MB时间限制:1 S标准输入输出题目类型:传统评测方式:文本比较上传者:外部导入提交:5923通过:2944
题目描述
小蓝有很多数字卡片,每张卡片上都是数字0 到9。
小蓝准备用这些卡片来拼一些数,他想从1 开始拼出正整数,每拼一个,就保存起来,卡片就不能用来拼其它数了。
小蓝想知道自己能从1 拼到多少。
例如,当小蓝有30 张卡片,其中0 到9 各3 张,则小蓝可以拼出1 到10,但是拼11 时卡片1 已经只有一张了,不够拼出11。
现在小蓝手里有0 到9 的卡片各2021 张,共20210 张,请问小蓝可以从1拼到多少?
提示:建议使用计算机编程解决问题。
#include<iostream>
#include <istream>
#include<algorithm>
#include <cstring>
#include <queue>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <stack>
#include <sstream>
#include <stdlib.h>
#include <iomanip>
#include <utility>
#define int long long
using namespace std;
signed main()
{
int a[10],cnt=1;
for (int i = 0; i <= 9; i++)
a[i] = 2021;
for (int i=1; i <= 50000; i++)
{
int num = i;
while (num > 0)
{
if (a[num % 10] == 0)
break;
else
{
a[num % 10]--;
num /= 10;
}
}
if (num == 0)
cnt++;
else
break;
}
cout << cnt;
}
//每张卡片用一次就减少一次,当需要的卡片为0时输出即可
1552: [蓝桥杯2021初赛] 货物摆放
内存限制:256 MB时间限制:1 S标准输入输出题目类型:传统评测方式:文本比较上传者:外部导入提交:3872通过:1771