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

news/2024/4/30 1:59:34

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;
}

后面两题不会,补;

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

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

相关文章

WPS二次开发专题:如何获取应用签名SHA256值

作者持续关注WPS二次开发专题系列&#xff0c;持续为大家带来更多有价值的WPS开发技术细节&#xff0c;如果能够帮助到您&#xff0c;请帮忙来个一键三连&#xff0c;更多问题请联系我&#xff08;QQ:250325397&#xff09; 在申请WPS SDK授权版时候需要开发者提供应用包名和签…

方案分享 | 嵌入式指纹方案

随着智能设备的持续发展&#xff0c;指纹识别技术成为了现在智能终端市场和移动支付市场中占有率最高的生物识别技术。凭借高识别率、短耗时等优势&#xff0c;被广泛地运用在智能门锁、智能手机、智能家居等设备上。 我们推荐的品牌早已在2015年进入指纹识别应用领域&#xff…

【干货】零售商的商品规划策略

商品规划&#xff0c;无疑是零售业的生命之源&#xff0c;是推动业务腾飞的强大引擎。一个精心策划的商品规划策略&#xff0c;不仅能帮助零售商在激烈的市场竞争中稳固立足&#xff0c;更能精准捕捉客户需求&#xff0c;实现利润最大化。以下&#xff0c;我们将深入探讨零售商…

C++ //练习 11.14 扩展你在11.2.1节练习(第378页)中编写的孩子姓到名的map,添加一个pair的vector,保存孩子的名和生日。

C Primer&#xff08;第5版&#xff09; 练习 11.14 练习 11.14 扩展你在11.2.1节练习&#xff08;第378页&#xff09;中编写的孩子姓到名的map&#xff0c;添加一个pair的vector&#xff0c;保存孩子的名和生日。 环境&#xff1a;Linux Ubuntu&#xff08;云服务器&#x…

【超简单】基于PaddleSpeech搭建个人语音听写服务

一、【超简单】之基于PaddleSpeech搭建个人语音听写服务 1.需求分析 亲们,你们要写会议纪要嘛?亲们,你们要写会议纪要嘛?亲们,你们要写会议纪要嘛?当您面对成吨的会议录音,着急写会议纪要而不得不愚公移山、人海战术?听的头晕眼花,听的漏洞百出,听的怀疑人生,那么你…

开启 Keep-Alive 可能会导致http 请求偶发失败

大家好&#xff0c;我是蓝胖子&#xff0c;说起提高http的传输效率&#xff0c;很多人会开启http的Keep-Alive选项&#xff0c;这会http请求能够复用tcp连接&#xff0c;节省了握手的开销。但开启Keep-Alive真的没有问题吗&#xff1f;我们来细细分析下。 最大空闲时间造成请求…