【第16届蓝桥杯 | 软件赛】CB组省赛第二场

news2025/6/4 23:09:40

在这里插入图片描述

个人主页:Guiat
归属专栏:算法竞赛

在这里插入图片描述

文章目录

  • A. 密密摆放(5分填空题)
  • B. 脉冲强度之和(5分填空题)
  • C. 25 之和
  • D. 旗帜
  • E. 数列差分
  • F. 树上寻宝
  • G. 翻转硬币
  • H. 破解信息

正文

总共8道题。

A. 密密摆放(5分填空题)

【题目】密密摆放

【分析】
考察观察,首先考虑最多盒子数量:200 * 250 * 240 / (30 * 40 * 50),观察到正好可以被整除,即最终结果。

【答案】200

【AC_Code】

#include <iostream>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

void solve() { cout << 200 * 250 * 240 / (30 * 40 * 50) << '\n'; }

int main()
{
    IOS int _ = 1;   // cin >> _;
    while (_ --) solve();
    
    return 0;
}

B. 脉冲强度之和(5分填空题)

【题目】脉冲强度之和

【分析】
考察数学和观察。
p = k + (k + 1) + (k + 2) + ··· + (k + 9) = (k + (k + 9)) * 10 / 2 = 10k + 45(k为正整数)
1 <= p <= 20255202且各个数位上的数字都相同 => p = 55、555、5555、55555、555555、5555555
所以 ans = 55 + 555 + 5555 + 55555 + 555555 + 5555555

【答案】6172830

【AC_Code】

#include <iostream>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

void solve() { cout << 55 + 555 + 5555 + 55555 + 555555 + 5555555 << '\n'; }

int main()
{
    IOS int _ = 1;   // cin >> _;
    while (_ --) solve();
    
    return 0;
}

C. 25 之和

【题目】25 之和

【AC_Code】

#include <iostream>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

void solve()
{
    int n; cin >> n;
    cout << (n + (n + 24)) * 25 / 2 << '\n';
}

int main()
{
    IOS int _ = 1;   // cin >> _;
    while (_ --) solve();
    
    return 0;
}

D. 旗帜

【题目】旗帜

【分析】

优先找规律。

在这里插入图片描述
在这里插入图片描述
观察上面两张图,总结出规律:(A下标之和) % 7 == 1 或 5,满足题目要求,找出规律后代码就很好写了。

【AC_Code】

#include <iostream>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

string s = "LANQIAO"; int ans;

void solve()
{
    int h, w; cin >> h >> w;
    for (int i = 0; i < h; i ++) for (int j = 0; j < w; j ++)
    {
    	if ((i + j) % 7 == 1 || (i + j) % 7 == 5) ans ++;
    	// if (s[(i + j) % 7] == 'A') ans ++;
	}
	cout << ans << '\n';
}

int main()
{
    IOS; int _ = 1;   // cin >> _;
    while (_ --) solve();
    
    return 0;
}

E. 数列差分

【题目】数列差分

【分析】
贪心 + 排序 + 双指针。
贪心思路:让较大的 a[i] 尽量匹配较大的 b[j],无法匹配时调整 b[j](ans ++)。

可视化理解(双指针)
在这里插入图片描述
讲解完毕。

【AC_Code】

#include <iostream>
#include <algorithm>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 1e5 + 10; int a[N], b[N], ans;

void solve()
{
    int n; cin >> n;
    for (int i = 0; i < n; i ++) cin >> a[i];
	for (int i = 0; i < n; i ++) cin >> b[i];
	sort(a, a + n); sort(b, b + n);
	int i = n - 1, j = n - 1;
	while (j != -1)
	{
		if (a[i] - b[j] <= 0) ans ++, j --;
		else i --, j --;
	}
	cout << ans << '\n';
}

int main()
{
    IOS; int _ = 1;   // cin >> _;
    while (_ --) solve();
    
    return 0;
}

F. 树上寻宝

【题目】树上寻宝

【分析】

本题用dfs做就好了。

  • 题意:给定一棵树,每个节点有一个权值。求距离根节点不超过 2k 的所有节点的权值之和。
  • 思路:DFS遍历:计算每个深度(距离根节点的边数)的节点权值和。
  • 累加结果:将深度不超过 2k 的所有节点的权值相加。
  • 深度计算:deep[i] 表示深度为 i 的所有节点的权值和。
  • 结果范围:题目要求不超过 k 条边,即深度不超过 2k(因为每条边连接两个节点)。

【AC_Code】

#include <iostream>
#include <vector>
#include <algorithm>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;

const int N = 1e5 + 10;
vector<int> aList[N]; ll w[N], deep[N], ans;

void dfs(int now, int fa, int step)
{
	deep[step] += w[now - 1];
	for (int a : aList[now]) if (a != fa) dfs(a, now, step + 1);
}

void solve()
{
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; i ++) cin >> w[i];
	for (int i = 0; i < n - 1; i ++)
	{
		int u, v; cin >> u >> v;
		aList[u].push_back(v); aList[v].push_back(u);
	}
	dfs(1, -1, 0);
	for (int i = 0; i <= min(n, 2 * k); i ++) ans += deep[i];
	cout << ans << '\n';
}

int main()
{
	IOS int _ = 1;   // cin >> _;
	while (_ --) solve();
	
	return 0;
}

G. 翻转硬币

【题目】翻转硬币

【分析】

【AC_Code】

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 

using namespace std;

const int N = 1e3 + 5; int n, m, a[N][N], dp[N][2][2];

int calculate(int row, int prev, int curr, int next)
{
    int res = 0;
    for (int i = 1; i <= m; ++i)
	{
        int cnt = 0;
        if (i > 1 && a[row][i] == a[row][i - 1]) cnt++;
        if (i < m && a[row][i] == a[row][i + 1]) cnt++;
        if (row > 1 && !(prev == curr ^ a[row][i] == a[row - 1][i])) cnt++;
        if (row < n && !(curr == next ^ a[row][i] == a[row + 1][i])) cnt++;
        res += cnt * cnt;
    }
    return res;
}

void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
	{
        string s; cin >> s;
        for (int j = 1; j <= m; ++j) a[i][j] = s[j - 1] - '0';
    }
    dp[2][0][0] = calculate(1, 0, 0, 0); dp[2][0][1] = calculate(1, 0, 1, 0);
    dp[2][1][0] = calculate(1, 0, 0, 1); dp[2][1][1] = calculate(1, 0, 1, 1);
    for (int i = 3; i <= n + 1; ++i)
	{
        dp[i][0][0] = max(dp[i - 1][0][0] + calculate(i - 1, 0, 0, 0), 
                       dp[i - 1][0][1] + calculate(i - 1, 1, 0, 0));
        dp[i][0][1] = max(dp[i - 1][1][0] + calculate(i - 1, 0, 1, 0), 
                       dp[i - 1][1][1] + calculate(i - 1, 1, 1, 0));
        dp[i][1][0] = max(dp[i - 1][0][0] + calculate(i - 1, 0, 0, 1), 
                       dp[i - 1][0][1] + calculate(i - 1, 1, 0, 1));
        dp[i][1][1] = max(dp[i - 1][1][0] + calculate(i - 1, 0, 1, 1), 
                       dp[i - 1][1][1] + calculate(i - 1, 1, 1, 1));
    }
    int ans = max( { dp[n + 1][0][0], dp[n + 1][0][1], dp[n + 1][1][0], dp[n + 1][1][1] } );
    cout << ans << "\n";
}

int main()
{
    IOS int _ = 1;
    while (_ --) solve();
    
    return 0;
}

H. 破解信息

【题目】破解信息

【分析】
简化题意:按序输出输入字符串的最大字符。

【AC_Code】

#include <iostream>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

void solve()
{
	string s; cin >> s; char maxC = 'a'; int pos = 0, cnt = 0;
	for (int i = 0; i < s.length(); i ++)
	{
		if (maxC < s[i]) maxC = s[i], i = pos;
	}
	for (char c : s) if (c == maxC) cnt ++;
	while (cnt --) cout << maxC; cout << '\n';
}

int main()
{
	IOS int _ = 1;   // cin >> _;
	while (_ --) solve();
	
	return 0;
}

结语
感谢您的阅读!期待您的一键三连!欢迎指正!

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2396905.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

AR/MR实时光照阴影开发教程

一、效果演示 1、PICO4 Ultra MR 发光的球 2、AR实时光照 二、实现原理 PICO4 Ultra MR开发时&#xff0c;通过空间网格能力扫描周围环境&#xff0c;然后将扫描到的环境网格材质替换为一个透明材质并停止扫描&#xff1b;基于Google ARCore XR Plugin和ARFoundation进行安卓手…

【汽车电子入门】一文了解LIN总线

前言&#xff1a;LIN&#xff08;Local Interconnect Network&#xff09;总线&#xff0c;也就是局域互联网的意思&#xff0c;它的出现晚于CAN总线&#xff0c;于20世纪90年代末被摩托罗拉、宝马、奥迪、戴姆勒、大众以及沃尔沃等多家公司联合开发&#xff0c;其目的是提供一…

【笔记】为 Python 项目安装图像处理与科学计算依赖(MINGW64 环境)

&#x1f4dd; 为 Python 项目安装图像处理与科学计算依赖&#xff08;MINGW64 环境&#xff09; &#x1f3af; 安装目的说明 本次安装是为了在 MSYS2 的 MINGW64 工具链环境中&#xff0c;搭建一个完整的 Python 图像处理和科学计算开发环境。 主要目的是支持以下类型的 Pyth…

智能守护电网安全:探秘输电线路测温装置的科技力量

在现代电力网络的庞大版图中&#xff0c;输电线路如同一条条 “电力血管”&#xff0c;日夜不息地输送着能量。然而&#xff0c;随着电网负荷不断增加&#xff0c;长期暴露在户外的线路&#xff0c;其线夹与导线在电流热效应影响下&#xff0c;极易出现温度异常。每年因线路过热…

【Hot 100】118. 杨辉三角

目录 引言杨辉三角我的解题代码优化优化说明 &#x1f64b;‍♂️ 作者&#xff1a;海码007&#x1f4dc; 专栏&#xff1a;算法专栏&#x1f4a5; 标题&#xff1a;【Hot 100】118. 杨辉三角❣️ 寄语&#xff1a;书到用时方恨少&#xff0c;事非经过不知难&#xff01; 引言 …

useMemo useCallback 自定义hook

useMemo & useCallback & 自定义hook useMemo 仅当依赖项发生变化的时候&#xff0c;才去重新计算&#xff1b;其他状态变化时则不去做不必要的计算。 useCallback 缓存函数。但是使用注意&#x1f4e2; &#xff0c;useCallback没有特别明显的优化。 *合适的场景——父…

ffmpeg 的视频格式转换 c# win10

1&#xff0c;下载ffmpeg &#xff0c;并设置环境变量。 ffmpeghttps://www.gyan.dev/ffmpeg/builds/ 2.新建.net 9.0 winform using System; using System.Diagnostics; using System.Text; using System.Windows.Forms;namespace WinFormsApp11 {public partial class Fo…

【irregular swap】An Examination of Fairness of AI Models for Deepfake Detection

文章目录 An Examination of Fairness of AI Models for Deepfake Detection背景points贡献深伪检测深伪检测审计评估检测器主要发现评估方法审计结果训练分布和方法偏差An Examination of Fairness of AI Models for Deepfake Detection 会议/期刊:IJCAI 2021 作者: 背景…

【JAVA】注解+元注解+自定义注解(万字详解)

&#x1f4da;博客主页&#xff1a;代码探秘者 ✨专栏&#xff1a;《JavaSe》 其他更新ing… ❤️感谢大家点赞&#x1f44d;&#x1f3fb;收藏⭐评论✍&#x1f3fb;&#xff0c;您的三连就是我持续更新的动力❤️ &#x1f64f;作者水平有限&#xff0c;欢迎各位大佬指点&…

【Doris基础】Apache Doris中的Version概念解析:深入理解数据版本管理机制

目录 引言 1 Version概念基础 1.1 什么是Version 1.2 Version的核心作用 1.3 Version相关核心概念 2 Version工作机制详解 2.1 Version在数据写入流程中的作用 2.2 Version在数据查询流程中的作用 2.3 Version的存储结构 3 Version的进阶特性 3.1 Version的合并与压…

【图像处理基石】如何进行图像畸变校正?

图像畸变校正常用于计算机视觉、摄影测量学和机器人导航等领域&#xff0c;能够修正因镜头光学特性或传感器排列问题导致的图像失真。下面我将介绍几种常用的图像畸变校正算法&#xff0c;并提供Python实现和测试用例。 常用算法及Python实现 1. 径向畸变校正 径向畸变是最常…

电力系统时间同步系统

电力系统中&#xff0c;电压、电流、功率变化等特征量测量都是时间相关函数[1]&#xff0c;统一精准的时间源对于电网安全稳定运行至关重要&#xff0c;因此&#xff0c;电力系统运行规程[2]中明确要求继电保护装置、自动化装置、安全稳定控制系统、能量管理系统和生产信息管理…

Vue使用toFixed保留两位小数的三种写法

第一种&#xff1a;直接写在js里面&#xff0c;这是最简单的 val.toFixed(2)第二种&#xff1a;在ElementUi表格中使用 第三种&#xff1a;在取值符号中使用 {{}} 定义一个方法 towNumber(val) { return val.toFixed(2) } 使用 {{ towNumber(row.equiV…

Arch安装botw-save-state

devkitPro https://blog.csdn.net/qq_39942341/article/details/148387077?spm1001.2014.3001.5501 cargo https://blog.csdn.net/qq_39942341/article/details/148387783?spm1001.2014.3001.5501 megaton https://blog.csdn.net/qq_39942341/article/details/148388164?spm…

电脑为什么换个ip就上不了网了

在日常使用电脑上网时&#xff0c;很多人可能遇到过这样的问题&#xff1a;当IP地址发生变化后&#xff0c;突然就无法连接网络了。当电脑更换IP地址后无法上网&#xff0c;这一现象可能由多种因素导致&#xff0c;涉及网络配置、硬件限制或运营商策略等层面。以下是系统性分析…

github 2FA双重认证丢失解决

文章目录 前言一. 凭借ssh 解锁步骤1.1 要求输入设备码1.2.进入二重验证界面1.3.开始2FA恢复1.4.选择使用ssh验证 二.预防措施2.1 云盘上传git_recover_codes.txt2.2 开启多源FA认证2.2.1 大陆无法使用手机验证码 三.参考资料 前言 场景&#xff1a;没有意识到github recovery …

linux驱动 - 5: simple usb device驱动

参考第2节, 准备好编译环境并实现hello.ko: linux驱动 - 2: helloworld.ko_linux 驱动开发 hello world ko-CSDN博客 下面在hello模块的基础上, 添加代码, 实现一个usb设备驱动的最小骨架. #include <linux/init.h> #include <linux/module.h> #include <lin…

ETL脚本节点使用的方式

随着大数据时代的到来&#xff0c;企业对数据处理的需求日益增长&#xff0c;ETL 作为数据整合的关键技术&#xff0c;逐渐走进我们的视野。本文将为您揭秘 ETL 脚本节点的使用方式&#xff0c;助您轻松驾驭数据处理新境界。 一、ETL脚本的优势 1.提高效率&#xff1a;ETL 脚…

PH热榜 | 2025-06-02

1. Circuit Tracer 标语&#xff1a;Anthropic的开放工具&#xff1a;让我们了解AI是如何思考的 介绍&#xff1a;Anthropic的开源工具Circuit Tracer可以帮助研究人员理解大型语言模型&#xff08;LLMs&#xff09;&#xff0c;它通过将内部计算可视化为归因图的方式展现相关…

: influxdb + grafana+JMeter

influxdb和Grafana 不安装在被测机器上&#xff0c;可以统一放到一台机器上面 1、influxdb&#xff1a;一种时序数据库&#xff0c; 可以永久性保存数据【除非手动清除和数据库坏了】 2、Grafana&#xff1a;grafana是一款用go编写的开源应用&#xff0c;用于大规模指标数据的可…