第十三届蓝桥杯大赛软件赛省赛C/C++ 大学 B 组 题解

2024-04-09 14:52

本文主要是介绍第十三届蓝桥杯大赛软件赛省赛C/C++ 大学 B 组 题解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

VP比赛链接 : 

数据加载中... - 蓝桥云课

1 . 九进制 转 十进制

直接模拟就好了

#include <iostream>
using namespace std;
int main()
{// 请在此输入您的代码int x = 2+2*9+2*81*9;cout << x << endl ;return 0;
}

2 . 顺子日期

枚举出每个情况即可 : 总共14个 ;

#include <iostream>
using namespace std;
int main()
{// 请在此输入您的代码// 0120 0121 .. 29 : 10// 1月 : 10// 1012// 1123//1230// 1231cout << 14 << endl ;return 0;
}

3 . 刷题统计

模拟即可 : 

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define lowbit(x) (x&(-x))
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(), a.end()
#define int long long
typedef long long LL;using namespace std;inline void solve(){LL a , b , n ; cin >> a >> b >> n ;LL x = 5*a + 2*b ;LL w = n / x ;LL ans = w * 7 ;n -= w * x ;LL f = n % x ;for(int i=1;i<=5&&n>0;i++){n-=a ; ans ++ ;} for(int i=1;i<=2&&n>0;i++){n -= b ;ans ++ ;}cout << ans << endl ;
}signed main()
{IOSint _ = 1;while(_ --) solve();return 0;
}

4 . 修剪灌木

对于每一颗灌木最大是2*(距离两边较大的距离 ) ;

然后遍历即可 : 

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define lowbit(x) (x&(-x))
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(), a.end()
#define int long long
typedef long long LL;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;using namespace std;inline void solve() {int n ; cin >> n ;for(int i=1;i<=n;i++){int ans = max(2*(i-1),2*(n-i));cout << ans << endl ;}
}signed main()
{IOSint _ = 1;while (_--) solve();return 0;
}

5 . X进制减法

根据题目意思去模拟 , 对于每一位先计算数位=max(2,max(a[i],b[i])+1);

然后计算每一位的权重 : 由前面的地推过来即可 ;

然后分别算出A和B的值,相减即可 ;

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
typedef long long LL;
const int mod = 1e9+7;
const int N = 1e5+10;
using namespace std;// 321
// 第一位 1
// 3 * 20 + 2 * 2 + 1 * 1 = 64int a[N] , b[N] ,w[N], mul[N] ;inline void solve(){int n ; cin >> n ;int x, y ; cin >> x ;for(int i=x;i>=1;i--) cin >> a[i] ;cin >> y ;for(int i=y;i>=1;i--) cin >> b[i] ;//1是低位 int ma = max(x , y) ;for(int i=1;i<=ma;i++) mul[i] = max(2,max(a[i],b[i])+1) ;//每一位的进制 w[1] = 1 ;for(int i=2;i<=ma;i++){w[i] = 1LL * w[i-1] * mul[i-1] % mod ;}LL A = 0 , B = 0 ;for(int i=1;i<=x;i++) A = (A + 1LL * a[i] * w[i]  ) % mod ;for(int i=1;i<=y;i++) B = (B + 1LL * b[i] * w[i]  ) % mod ;cout << (A - B + mod) % mod  << endl ;
}signed main()
{IOSint _ = 1;while(_ --) solve();return 0;
}

6 . 统计子矩阵

前缀和 + 滑动窗口

先计算出每一列的前缀和 , 然后用滑动窗口来夹每一列,对于每个合适的窗口,ans加上窗口长度 ;

详细请看代码 : 

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
typedef long long LL;
const int mod = 1e9+7;
const int N = 510;
using namespace std;LL a[N][N] ;inline void solve(){LL n,m,k;cin>>n>>m>>k;for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){cin >> a[i][j] ;a[i][j]+=a[i-1][j];// 统计每一列的前缀和 }LL ans = 0 ;for(int i=1;i<=n;i++){for(int j=i;j<=n;j++){// 夹中间LL sum = 0 ;int l = 1 , r = 1 ;while(r<=m){sum += a[j][r]-a[i-1][r] ;while(sum>k){sum -= a[j][l] - a[i-1][l] ;l ++ ;}ans += r - l + 1 ;r++ ;}}}cout << ans << endl ;
}signed main()
{IOSint _ = 1;while(_ --) solve();return 0;
}

7 . 积木画

状态压缩dp,不会

8 . 扫雷

实属简单,模拟即可 : 

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
typedef long long LL;
const int mod = 1e9+7;
const int N = 110;
using namespace std;int a[N][N] ,b[N][N] ;int dx[8] = {0,0,1,-1,1,1,-1,-1};
int dy[8] = {1,-1,0,0,1,-1,1,-1};inline void solve(){int n , m ; cin >> n >> m ;for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin >> a[i][j] ;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){if(a[i][j]==1){b[i][j] = 9 ;continue ;}int cnt = 0 ;for(int p=0;p<8;p++){int x = i + dx[p] , y = j + dy[p] ;if(x>=1&&x<=n&&y>=1&&y<=m&&a[x][y]==1) cnt ++ ;}b[i][j] = cnt ;}}for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout << b[i][j] << " " ;}cout << endl ;}}signed main()
{IOSint _ = 1;while(_ --) solve();return 0;
}

后面两题不会,补;

这篇关于第十三届蓝桥杯大赛软件赛省赛C/C++ 大学 B 组 题解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/888460

相关文章

C++ move 的作用详解及陷阱最佳实践

《C++move的作用详解及陷阱最佳实践》文章详细介绍了C++中的`std::move`函数的作用,包括为什么需要它、它的本质、典型使用场景、以及一些常见陷阱和最佳实践,感兴趣的朋友跟随小编一起看... 目录C++ move 的作用详解一、一句话总结二、为什么需要 move?C++98/03 的痛点⚡C++

详解C++ 存储二进制数据容器的几种方法

《详解C++存储二进制数据容器的几种方法》本文主要介绍了详解C++存储二进制数据容器,包括std::vector、std::array、std::string、std::bitset和std::ve... 目录1.std::vector<uint8_t>(最常用)特点:适用场景:示例:2.std::arra

C++构造函数中explicit详解

《C++构造函数中explicit详解》explicit关键字用于修饰单参数构造函数或可以看作单参数的构造函数,阻止编译器进行隐式类型转换或拷贝初始化,本文就来介绍explicit的使用,感兴趣的可以... 目录1. 什么是explicit2. 隐式转换的问题3.explicit的使用示例基本用法多参数构造

C++,C#,Rust,Go,Java,Python,JavaScript的性能对比全面讲解

《C++,C#,Rust,Go,Java,Python,JavaScript的性能对比全面讲解》:本文主要介绍C++,C#,Rust,Go,Java,Python,JavaScript性能对比全面... 目录编程语言性能对比、核心优势与最佳使用场景性能对比表格C++C#RustGoJavapythonjav

C++打印 vector的几种方法小结

《C++打印vector的几种方法小结》本文介绍了C++中遍历vector的几种方法,包括使用迭代器、auto关键字、typedef、计数器以及C++11引入的范围基础循环,具有一定的参考价值,感兴... 目录1. 使用迭代器2. 使用 auto (C++11) / typedef / type alias

C++ scoped_ptr 和 unique_ptr对比分析

《C++scoped_ptr和unique_ptr对比分析》本文介绍了C++中的`scoped_ptr`和`unique_ptr`,详细比较了它们的特性、使用场景以及现代C++推荐的使用`uni... 目录1. scoped_ptr基本特性主要特点2. unique_ptr基本用法3. 主要区别对比4. u

C++11中的包装器实战案例

《C++11中的包装器实战案例》本文给大家介绍C++11中的包装器实战案例,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录引言1.std::function1.1.什么是std::function1.2.核心用法1.2.1.包装普通函数1.2.

C++多线程开发环境配置方法

《C++多线程开发环境配置方法》文章详细介绍了如何在Windows上安装MinGW-w64和VSCode,并配置环境变量和编译任务,使用VSCode创建一个C++多线程测试项目,并通过配置tasks.... 目录下载安装 MinGW-w64下载安装VS code创建测试项目配置编译任务创建 tasks.js

C++ 多态性实战之何时使用 virtual 和 override的问题解析

《C++多态性实战之何时使用virtual和override的问题解析》在面向对象编程中,多态是一个核心概念,很多开发者在遇到override编译错误时,不清楚是否需要将基类函数声明为virt... 目录C++ 多态性实战:何时使用 virtual 和 override?引言问题场景判断是否需要多态的三个关

C++简单日志系统实现代码示例

《C++简单日志系统实现代码示例》日志系统是成熟软件中的一个重要组成部分,其记录软件的使用和运行行为,方便事后进行故障分析、数据统计等,:本文主要介绍C++简单日志系统实现的相关资料,文中通过代码... 目录前言Util.hppLevel.hppLogMsg.hppFormat.hppSink.hppBuf