2021年蓝桥杯C组题解-第十二届蓝桥杯大赛个人赛省赛(软件类)真题

真题见如下链接

https://www.lanqiao.cn/courses/2786/learning/?id=280827

第一题

如果实在不会了直接char强制转换int也可以做啊,忽略了。

第二题

科普一下:1Mb = 1024Kb = 1024 * 1024b
可以通过sizeof(int)得到 int的字节数为4
所以这道题的答案为256*1024*1024/4=67108864

第三题
一道简单的模拟题,直接看代码。

//Problem C
#include <iostream>
using namespace std;
int n[10];//用于存储每一个数字卡片剩余张数
bool check(int a)
{
	while (a > 0)
	{
		int tmp = a % 10;
		a /= 10;
		n[tmp]--;//剩余张数减一
		if (n[tmp] == -1)//这个数字无法组合
		{
			return true;
		}
	}
	return false;
}
int main()
{
	for (int i = 0; i < 10; i++)
	{
		n[i] = 2021;//初始化,每个数字都有2021张
	}
	int i = 1;
	for (i;; i++)
	{
		bool f = check(i);
		if (f)
			break;
	}
	cout << i - 1 << endl;
	return 0;
}

第四题
略,等学完图论补充。

第五题

#include <iostream>
#include <cstdio>
#define LL long long
using namespace std;
int main()
{
	LL t;
	scanf("%lld", &t);
	t /= 1000;//毫秒转秒
	t %= 86400;//精确到一天的秒数
	int hh = t / 3600;
	t %= 3600;
	int mm = t / 60;
	t %= 60;
	int ss = t;
	printf("%0.2d:%0.2d:%0.2d\n", hh, mm, ss);
	return 0;
}

第六题
很妙啊,参考https://zhuanlan.zhihu.com/p/37895166

#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int index = 1, count = 1, weight = 1;
	while (weight < n) {
		count++;
		index *= 3;
		weight += index;
	}
	cout << count << endl;
	return 0;
}

第七题
杨辉三角形
参考https://blog.csdn.net/weixin_44091134/article/details/116748883
这是我的注解
在这里插入图片描述

#include <iostream>
#include <cmath>
#define LL long long
using namespace std;
int N;
LL c(int a, int b)
{
	LL res = 1;
	for (int i = a, j = 1; j <= b; i--, j++)
	{
		res = res * i / j;
		if (res > N)//大于N没有意义
			return res;
	}
	return res;
}
bool check(int k)//二分查找
{
	int l = 2 * k;//左边界
	int r = max(l, N);//右边界
	while (l < r)
	{
		int mid = (l + r) / 2;
		if (c(mid, k) >= N)
		{
			r = mid;
		}
		else
		{
			l = mid + 1;
		}
	}
	if (c(r, k) != N)
	{
		//cout << k << " not found" << endl;
		return false;//没有找到
	}
	cout << 1ll * (r + 1) * r / 2 + k + 1 << endl;
	return true;
}
int main()
{
	cin >> N;
	for (int i = 16; i >= 0; i--)//从大到小保证找到的数出现的最早
	{
		if (check(i))
			break;
	}
	return 0;
}

第八题
看见数据结构就头疼,等学完了再说。
第九题
还在思考中。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值