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

news2024/10/6 17:30:11

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]);
		}
		else
			continue;

		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]));
			else
				g[i][3] = min(g[i - 1][3], g[i - 1][2] * a[i]);
		}else
			continue;
		
		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]);
		}
		else
			continue;

		
		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]));
			else
				f[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]));
			else
				g[i][5] = min(g[i - 1][5], g[i - 1][4] * a[i]);
		}else
			continue;

		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.coloradmin.cn/o/1460373.html

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

相关文章

为全志D1开发板移植LVGL日历控件和显示天气

利用TCP封装HTTP包请求天气信息 Linux还真是逐步熟悉中&#xff0c;现在才了解到Linux即没有原生的GUI&#xff0c;也没有应用层协议栈&#xff0c;所以要实现HTTP应用&#xff0c;必须利用TCP然后自己封装HTTP数据包。本篇即记录封装HTTP数据包&#xff0c;到心知天气请求天气…

亿道丨三防平板电脑厂家丨三防平板PDA丨三防工业平板:数字时代

在当今数字化时代&#xff0c;我们身边的世界变得越来越依赖于智能设备和无线连接。其中&#xff0c;三防平板PDA&#xff08;Personal Digital Assistant&#xff09;作为一种功能强大且耐用的数字工具&#xff0c;正在引领我们进入数字世界的全新征程。 三防平板PDA结合了平板…

在Win系统部署WampServer并实现公网访问本地服务【内网穿透】

目录 推荐 前言 1.WampServer下载安装 2.WampServer启动 3.安装cpolar内网穿透 3.1 注册账号 3.2 下载cpolar客户端 3.3 登录cpolar web ui管理界面 3.4 创建公网地址 4.固定公网地址访问 推荐 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0…

【Pytorch深度学习开发实践学习】B站刘二大人课程笔记整理lecture02 线性模型

课程网址 Pytorch深度学习实践 部分课件内容&#xff1a; 代码部分如下&#xff1a; import numpy as np import matplotlib.pyplot as pltx_data [1.0,2.0,3.0] y_data [2.0,4.0,6.0]def forward(x):return x * wdef loss(x,y):y_pred forward(x)return (y_pred - y) ** …

vue实现列表自动无缝滚动列表

大家好&#xff0c;今天给大家分享的知识是vue基于vue-seamless-scroll实现自动无缝滚动列表 一、实现自动滚动 最近在开发过程中遇到一个问题&#xff0c;就是需要实现自动滚动列表&#xff0c;效果图如下 就是这样一个列表在自动循环展示。在这里我是运用的 vue-seamless-sc…

Springboot AOP开发

Springboot AOP开发 一 AOP概述 AOP&#xff0c;即面向切面编程&#xff0c;简言之&#xff0c;面向方法编程。 针对方法&#xff0c;在方法的执行前或执行后使用&#xff0c;用于增强方法&#xff0c;或拓展。 二 AOP开发 1.引入 spring-boot-starter-aop 在SpringBoot项…

计算机视觉基础【OpenCV轻松入门】:获取图像的ROI

OpenCV的基础是处理图像&#xff0c;而图像的基础是矩阵。 因此&#xff0c;如何使用好矩阵是非常关键的。 下面我们通过一个具体的实例来展示如何通过Python和OpenCV对矩阵进行操作&#xff0c;从而更好地实现对图像的处理。 ROI&#xff08;Region of Interest&#xff09;是…

十三、集合进阶——单列集合 及 数据结构

单列集合 及 数据结构 13.1 集合体系结构13.1.2 单列集合1. Collection2.Collection 的遍历方式迭代器遍历增强for遍历Lambda表达式遍历 3.List集合List集合的特有方法List集合的遍历方式五种遍历方式对比 4.数据结构1).栈2).队列3&#xff09;数组4&#xff09;链表小结5&…

【程序员英语】【美语从头学】初级篇(入门)(笔记)Lesson 15 At the Department Store 在百货商店

《美语从头学初级入门篇》 注意&#xff1a;被 删除线 划掉的不一定不正确&#xff0c;只是不是标准答案。 文章目录 Lesson 15 At the Department Store 在百货商店会话A会话B笔记 Lesson 15 At the Department Store 在百货商店 会话A A: Can you help me, please? B: Sur…

世强硬创与SMT激光模板制造商光盛激光达成平台合作

近日&#xff0c;世强先进&#xff08;深圳&#xff09;科技股份有限公司&#xff08;下称“世强先进”&#xff09;与一家专注生产研发电子工业用工模具的企业——东莞光盛激光科技有限公司&#xff08;下称“光盛激光”&#xff09;达成平台合作。 据了解&#xff0c;光盛激光…

Facebook与数字创新:引领社交媒体的数字化革命

在当今数字化时代&#xff0c;社交媒体已经成为了人们日常生活中不可或缺的一部分。而在众多社交媒体平台中&#xff0c;Facebook作为领头羊&#xff0c;一直致力于推动数字创新&#xff0c;引领着社交媒体的数字化革命。本文将探讨Facebook在数字创新方面的表现&#xff0c;以…

绝地求生:图纸的加量不加价是否预示着蓝洞经营模式的转变

成长型武器目前作为PUBG中除了究极异色皮肤外的最高等级武器&#xff08;传说级&#xff09;&#xff0c;也是PUBG核心利润来源&#xff0c;十分的珍贵。 一把成长型武器的保底价格为3000碎片&#xff0c;而每次通过G-coin抽取会赠送10个碎片&#xff0c;也就是需要抽取三百次&…

外汇交易解决方案丨实时选取外汇行情多价源最优价

在外汇交易中&#xff0c;存在多个价源。多个价源之间&#xff0c;同一时刻的报价可能存在差异。在多个价源之间&#xff0c;实时选取最优价格具有重要意义&#xff0c;它有助于投资者获得更有利的交易执行价&#xff0c;降低交易成本&#xff0c;优化流动性&#xff0c;分散交…

中科大计网学习记录笔记(十四):多路复用与解复用 | 无连接传输:UDP

前言&#xff1a; 学习视频&#xff1a;中科大郑烇、杨坚全套《计算机网络&#xff08;自顶向下方法 第7版&#xff0c;James F.Kurose&#xff0c;Keith W.Ross&#xff09;》课程 该视频是B站非常著名的计网学习视频&#xff0c;但相信很多朋友和我一样在听完前面的部分发现信…

YOLO-NAS浅析

YOLO-NAS&#xff08;You Only Look Once - Neural Architecture Search&#xff09;是一种基于YOLO&#xff08;You Only Look Once&#xff09;的目标检测算法&#xff0c;结合神经架构搜索&#xff08;NAS&#xff09;技术来优化模型性能。 YOLO是一种实时目标检测算法&…

攻防世界-web-Training-WWW-Robots

题目信息 In this little training challenge, you are going to learn about the Robots_exclusion_standard. The robots.txt file is used by web crawlers to check if they are allowed to crawl and index your website or only parts of it. Sometimes these files rev…

pytest框架学习总结:失败用例如何处理?

当我们跑用例的时候&#xff0c;有些用例可能会失败&#xff0c;可以对失败的用例设置做如下管理&#xff1a; 1、失败重跑: --reruns 2 --reruns-delay 5 2、失败了停止执行后续的用例&#xff1a;pytest -x 3、设置最多失败多少用例会停止执行:pytest --maxfail2 4、跳过用例…

《Solidity 简易速速上手小册》第7章:智能合约的部署与交互(2024 最新版)

文章目录 7.1 合约的编译和部署7.1.1 基础知识解析更全面的理解部署准备 7.1.2 重点案例&#xff1a;部署一个投票合约案例 Demo&#xff1a;创建并部署投票合约案例代码VotingContract.sol部署脚本&#xff08;Truffle&#xff09; 测试和验证拓展功能 7.1.3 拓展案例 1&#…

基于vue框架的环保知识普及平台设计与实现

项目&#xff1a;基于vue框架的环保知识普及平台设计与实现 目 录 摘要 I Abstract II 第1章 引言 1 1.1 研究的背景 1 1.2 目的和意义 1 1.3 设计思路 1 1.4 研究的主要内容 2 第2章 相关原理和技术 3 2.1 B/S 模式体系结构 3 2.2 Springboot技术 4 2.3 访问数据库…

GitHub 2FA认证(双重身份验证)

GitHub 2FA认证&#xff08;双重身份验证&#xff09; GitHub 向部分用户发出警告&#xff1a;如果在北京时间 2024 年 1 月 19 日 08:00 前仍未启用双重验证&#xff08;2FA)&#xff0c;他们将被禁用部分功能。当然&#xff0c;这对于 GitHub 用户来说并不算意外&#xff0c…