2024牛客寒假算法基础集训营4(视频讲解题目)

news/发布时间2024/5/16 9:16:24

2024牛客寒假算法基础集训营4(视频讲解题目)

  • 视频链接
  • A
  • B
  • C
  • D
  • E
  • F
  • G、H(下面是hard版本的代码两个都可以过)

视频链接

2024牛客寒假算法基础集训营4(视频讲解题目)
在这里插入图片描述

A

#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f
using namespace std;void solve()
{int a, b ,k;cin >> a >> b >> k;if(a >= k * b){cout << "good" << endl;}else{cout << "bad" << endl;}}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;t = 1;//cin >> t;while(t--)solve();
}

B

#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f
using namespace std;void solve()
{int n; cin >> n;vector<int>a(n);int x = 0;for(int i = 0; i < n; i ++){cin >> a[i];x += (a[i] - 1);}if(x % 2){cout << "gui" << endl;}else{cout << "sweet" << endl;}}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;t = 1;// cin >> t;while(t--)solve();
}

C

#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int,int> pii;
void solve()
{int n, m, x, y;cin >> n >> m >> x >> y;x -- ,y --;vector<string> g(n + 10);for(int i = 0; i < n; i ++){cin >> g[i];}int p, q; cin >> p >> q;vector<pii>ops(q);for(int i = 0; i < q; i ++){cin >> ops[i].first >> ops[i].second;}while(p--){for(int j = 0; j < q; j ++){int op = ops[j].first, z = ops[j].second - 1;if(op == 1){char s = g[z][m - 1];for(int i = m - 1; i >= 1; i --){g[z][i] = g[z][i - 1];}g[z][0] = s;}else{char s = g[n - 1][z];for(int i = n - 1; i >= 1; i --){g[i][z] = g[i - 1][z];}g[0][z] = s;}}}cout << g[x][y] << endl;
}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;t = 1;// cin >> t;while(t--)solve();
}

D

#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f
#define int long long
using namespace std;void solve()
{int n; cin >> n;vector<int>a(n);for(int i = 0; i < n; i ++){cin >> a[i];}if(n == 1){cout << 1 << endl;return;}int s = 0;for(int i = 0; i < n; i ++){s += a[i];}int ans = 0;for(int i = 1; i <= s / i; i ++){if(s % i){continue;}int a = i, b = s / i;if(s / a >= n){ans ++;}if(a != b and s / b >= n){ans ++;}}cout << ans << endl;
}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;t = 1;//cin >> t;while(t--)solve();
}

E

#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f
#define int long long
using namespace std;void solve()
{int n, k; cin >> n >> k;vector<int>a(n + 1), s(n + 1);for(int i = 1; i <= n; i ++){cin >> a[i];s[i] = s[i - 1] + a[i];}int ans = 0;map<int,int>st;st[0] = 1;for(int i = 1; i <= n; i ++){int p = s[i] % k;if(st[p]){ans += st[p];st.clear();}st[p] ++;}cout << ans << endl;
}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;t = 1;//cin >> t;while(t--)solve();
}

F

#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f3f3f3f3f
#define int long long 
using namespace std;
const int N = 1e3 + 10;
int a[N];
int f[N][10], g[N][10], dp[N];
int has[N][N][2];
int cal(int x, int y){if(y - x + 1 < 6){return 0;}if(has[x][y - 1][0] != INF and has[x][y - 1][1] != INF){int res = max(has[x][y - 1][1], has[x][y - 1][0] - a[y]);return res;}for(int i = x; i <= y + 1; i ++){for(int j = 0; j <= 6; j ++){f[i][j] = -INF;g[i][j] = INF;}}for(int i = x; i <= y; i ++){if(i != x){f[i][1] = max(f[i - 1][1], a[i]);g[i][1] = min(g[i - 1][1], a[i]);}else{f[i][1] = a[i];g[i][1] = a[i];}if(i - x + 1 >= 2){g[i][2] = min(g[i - 1][2], g[i - 1][1] - a[i]);f[i][2] = max(f[i - 1][2], f[i - 1][1] - a[i]);}elsecontinue;if(i - x + 1 >= 3){if(g[i - 1][2] != INF){f[i][3] = max(f[i - 1][3], max(g[i - 1][2] * a[i], f[i - 1][2] * a[i]));}else{f[i][3] = max(f[i - 1][3], f[i - 1][2] * a[i]);}if(f[i - 1][2] != -INF)g[i][3] = min(g[i - 1][3], min(g[i - 1][2] * a[i], f[i - 1][2] * a[i]));elseg[i][3] = min(g[i - 1][3], g[i - 1][2] * a[i]);}elsecontinue;if(i - x + 1 >= 4){f[i][4] = max(f[i - 1][4], f[i - 1][3] - a[i]);g[i][4] = min(g[i - 1][4], g[i - 1][3] - a[i]);}elsecontinue;if(i - x + 1 >= 5){if(g[i - 1][4] != INF)f[i][5] = max(f[i - 1][5], max(g[i - 1][4] * a[i], f[i - 1][4] * a[i]));elsef[i][5] = max(f[i - 1][5], f[i - 1][4] * a[i]);if(f[i - 1][4] != -INF)g[i][5] = min(g[i - 1][5], min(g[i - 1][4] * a[i], f[i - 1][4] * a[i]));elseg[i][5] = min(g[i - 1][5], g[i - 1][4] * a[i]);}elsecontinue;if(i - x + 1 >= 6)f[i][6] = max(f[i - 1][6], f[i - 1][5] - a[i]);}int res = 0;int xx = 0;for(int i = x; i <= y; i ++){res = max(res, f[i][6]);xx = max(xx, f[i][5]);}has[x][y][1] = res;//选6个数字的最大值has[x][y][0] = xx;//选5个数字的最大值return res;
}
void solve()
{int n; scanf("%lld", & n);for(int i = 1; i <= n; i ++){scanf("%lld", a + i);}for(int i = 1; i <= n; i ++){for(int j = 1; j <= n; j ++){has[i][j][0] = has[i][j][1] = INF;}}for(int i = 1; i <= n; i ++){dp[i] = dp[i - 1];for(int j = 1; j <= i; j ++){dp[i] = max(dp[i], dp[j - 1] + cal(j, i));}}printf("%lld", dp[n]);
}signed main()
{int t = 1;while(t--)solve();
}

G、H(下面是hard版本的代码两个都可以过)

#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f
using namespace std;
const int N = 3e3 + 10;
char g[N][N];
int ul[N][N], ur[N][N], ls[N][N], rs[N][N];class BIT{
private:vector<long long>tre;int n;
public:BIT(int size): n(size), tre(size + 1, 0) {};public:int lowbit(int x){return x & -x;}void add(int pos, long long x){for(int i = pos; i <= n; i += lowbit(i))tre[i] = tre[i] + x;}long long sum(int pos){long long res = 0;for(int i = pos; i; i -= lowbit(i))res = res + tre[i];return res;}};
void solve()
{int n, m; cin >> n >> m;for(int i = 1; i <= n; i ++){string s; cin >> s;for(int j = 1; j <= m; j ++){g[i][j] = s[j - 1];}}for(int i = n; i >= 1; i --){for(int j = 1; j <= m; j ++){if(g[i][j] == '*'){ul[i][j] = ul[i + 1][j - 1] + 1;ur[i][j] = ur[i + 1][j + 1] + 1;ls[i][j] = ls[i][j - 1] + 1;}else{ul[i][j] = ur[i][j] = ls[i][j] = 0;}}for(int j = m; j >= 1; j --){if(g[i][j] == '*'){rs[i][j] = rs[i][j + 1] + 1;}else{rs[i][j] = 0;}}}long long ans = 0;for(int j = 1; j <= m; j ++){BIT t(n);//记录合法点的个数vector<vector<int>>del(n + 1);//记录在v这个点需要删除的点。for(int i = n; i >= 1; i --){if(g[i][j] == '*'){int v = i - min(ls[i][j], rs[i][j]) + 1;if(v >= 1){del[v].push_back(i);}int low = i + min(ul[i][j], ur[i][j]) - 1;ans += t.sum(low);t.add(i, 1);}for(auto x: del[i]){t.add(x, -1);}}}cout << ans << endl;
}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;t = 1;// cin >> t;while(t--)solve();
}

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

如若内容造成侵权/违法违规/事实不符,请联系编程老四网进行投诉反馈email:xxxxxxxx@qq.com,一经查实,立即删除!

相关文章

深入探索pdfplumber:从PDF中提取信息到实际项目应用【第94篇—pdfplumbe】

深入探索pdfplumber&#xff1a;从PDF中提取信息到实际项目应用 在数据处理和信息提取的过程中&#xff0c;PDF文档是一种常见的格式。然而&#xff0c;要从PDF中提取信息并进行进一步的分析&#xff0c;我们需要使用适当的工具。本文将介绍如何使用Python库中的pdfplumber库来…

华为OD机试真题-整数对最小和-2023年OD统一考试(C卷)-- Python3-开源

题目&#xff1a; 考察内容&#xff1a;双循环sortsum 代码&#xff1a; """ 题目分析&#xff1a; 求随机组合最小和 输入&#xff1a; 数组a个数&#xff0c; 数组元素 数组b个数&#xff0c;数组元素 对数个数输出&#xff1a; 和的最小值3 1 1 2 3 1 2 3…

时间获取、文件属性获取 2月20日学习笔记

执行两次代码&#xff0c;打印出两次执行过程中新增的文件及删除的文件 #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <stdio.h> #include <string.h> #include <dirent.h>#def…

Docker容器实战

"爱在&#xff0c;地图上&#xff0c;剥落~" Mysql 容器化安装 我们可以在 docker hub上&#xff0c;进入mysql的镜像仓库&#xff0c;找到适合的版本。 直接拉取镜像: docker pull mysql:latest 我们知道 msyql 的默认端口是 3306 &#xff0c;而且有密码&#x…

MYSQL-入门

一.安装和连接 1.1 安装 mysql安装教程&#xff1a; 2021MySql-8.0.26安装详细教程&#xff08;保姆级&#xff09;_2021mysql-8.0.26安装详细教程(保姆级)_mysql8.0.26_ylb呀的博客-cs-CSDN博客 workbench安装&#xff1a; MySQL Workbench 安装及使用-CSDN博客 1.2 配…

强大的文本绘图——PlantUML

PlantUML是一款开源工具&#xff0c;它允许用户通过简单的文本描述来创建UML图&#xff08;统一建模语言图&#xff09;。这种方法可以快速地绘制类图、用例图、序列图、状态图、活动图、组件图和部署图等UML图表。PlantUML使用一种领域特定语言&#xff08;DSL&#xff09;&am…

本机防攻击简介

定义 在网络中&#xff0c;存在着大量针对CPU&#xff08;Central Processing Unit&#xff09;的恶意攻击报文以及需要正常上送CPU的各类报文。针对CPU的恶意攻击报文会导致CPU长时间繁忙的处理攻击报文&#xff0c;从而引发其他业务的中断甚至系统的中断&#xff1b;大量正常…

idea如何在一个service窗口中显示多个服务教程

idea在service窗口中显示多个服务 展示效果如下: 找到.idea > workspace.xml 中找到 RunDashboard 替换成如下 <component name"RunDashboard"><option name"configurationTypes"><set><option value"SpringBootApplicatio…

反序列化字符串逃逸 [安洵杯 2019]easy_serialize_php1

打开题目 $_SESSION是访客与整个网站交互过程中一直存在的公有变量 然后看extract()函数的功能&#xff1a; extract($_POST)就是将post的内容作为这个函数的参数。 extract() 函数从数组中将变量导入到当前的符号表(本题的作用是将_SESSION的两个函数变为post传参) function…

【鸿蒙 HarmonyOS 4.0】状态管理

一、介绍 资料来自官网&#xff1a;文档中心 在声明式UI编程框架中&#xff0c;UI是程序状态的运行结果&#xff0c;用户构建了一个UI模型&#xff0c;其中应用的运行时的状态是参数。当参数改变时&#xff0c;UI作为返回结果&#xff0c;也将进行对应的改变。这些运行时的状…

氢气传感器与氢冷发电机:氢能应用中的关键技术及其安全监测

​ ​随着全球对可再生能源的迫切需求&#xff0c;氢能作为一种清洁、高效的能源形式&#xff0c;正逐渐受到人们的青睐。在氢能利用的过程中&#xff0c;氢气传感器和氢冷发电机成为了不可或缺的关键技术。然而&#xff0c;氢气作为一种易燃易爆的气体&#xff0c;其安全使…

P8630 [蓝桥杯 2015 国 B] 密文搜索

P8630 [蓝桥杯 2015 国 B] 密文搜索 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)https://www.luogu.com.cn/problem/P8630 题目分析 基本上是hash的板子&#xff0c;但实际上对于密码串&#xff0c;只要判断主串中任意连续的八个位置是否存在密码串即可&#xff1b;那么我们…

svn客户端下载、安装、使用

下载、使用 打开360软件管家&#xff0c;选怎宝库&#xff0c;搜索svn&#xff0c;点击安装 可以修改安装路径 使用 在桌面右键弹出菜单&#xff0c;点击 输入地址&#xff0c;点击ok 输入用户名、密码 &#xff0c;等待检出完成

机器学习基础(四)非监督学习的进阶探索

导语&#xff1a;上一节我们详细探索监督学习的进阶应用&#xff0c;详情可见&#xff1a; 机器学习基础&#xff08;三&#xff09;监督学习的进阶探索-CSDN博客文章浏览阅读296次&#xff0c;点赞13次&#xff0c;收藏11次。监督学习作为机器学习的一个主要分支&#xff0c;…

基础中的基础!吴恩达deeplearning.ai:如何搭建一个神经网络

在前面几篇博客的学习之后&#xff0c;你应该了解了如何写出Tensorflow有关的代码&#xff0c;如何在Tensorflow中搭建一个层以及如何在Tensorflow之中实现前向推理&#xff08;链接&#xff09;&#xff0c;也了解了Tensorflow有关的数据形式&#xff08;链接&#xff09; 今天…

深度学习介绍

02-深度学习介绍 1 AI地图2 深度学习任务2.1 图片分类2.2 物体检测和分割2.3 样式迁移2.4 人脸合成2.5 文字生成图片2.6 文字生成2.7 无人驾驶 3 案例研究4 question 1 AI地图 自然语言处理是感知的范围&#xff0c;人几秒内科研感知。 2 深度学习任务 2.1 图片分类 https:/…

Linux离线安装插件

当公司Linux环境无外网情况下&#xff0c;需要先下载好离线安装包&#xff0c;然后上传到服务器&#xff0c;进行安装。 这里介绍一个下载插件安装包的网站&#xff0c;可以搜索到lrzsz、lsof、telnet、unzip、zip等安装包 搜索到想要的插件安装包后&#xff0c;下载并上传到服…

基于Java jsp+mysql+Spring的汽车出租平台租赁网站平台设计和实现

基于Java jspmysqlSpring的汽车出租平台租赁网站平台设计和实现 博主介绍&#xff1a;5年java开发经验&#xff0c;专注Java开发、定制、远程、文档编写指导等,csdn特邀作者、专注于Java技术领域 作者主页 央顺技术团队 Java毕设项目精品实战案例《1000套》 欢迎点赞 收藏 ⭐留…

【若依(ruoyi)】Java---如何在Apifox上传params参数--延伸--如何在Apifox上传Map类型参数

在使用若依开发过程中写接口的时候想在params中添加参数,但是使用params.key这种形式在后端是接收不到传过来的参数的,于是百般调研(百度),终于找到一个解决办法,就是在参数前后加上%5B和%5D,这两个参数会被编译为"["和"]",于是就对得上了,后端成功接受到参…

Covalent Network(CQT)发展新里程碑:SOC 2 数据安全认证通过,进一步加强了其人工智能支持

Covalent Network&#xff08;CQT&#xff09;现已完成并通过了严格的 Service Organization Control&#xff08;SOC) 2 Type II 的合规性审计&#xff0c;通过由备受行业认可的机构执行&#xff0c;进一步证明了 Covalent Network&#xff08;CQT&#xff09;团队坚定不移地致…
推荐文章