【蓝桥杯】第十五届蓝桥杯C/C++B组省赛补题

文章目录

    • 估分
    • 试题 A: 握手问题
    • 试题 B: 小球反弹
    • 试题 C: 好数
    • 试题 D: R 格式
    • 试题 E: 宝石组合
    • 试题 F: 数字接龙
    • 试题 G: 爬山
    • 试题 H: 拔河

估分

测试网址:民间测试数据

5 + 0 + 9 + 5 + 2 + 5 + 18 + 2 = 46 5 + 0 + 9 + 5 + 2 + 5 + 18 + 2 =46 5+0+9+5+2+5+18+2=46

试题 A: 握手问题

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> PII;

void solve() {
	set<PII> s;
	int res = 7 * 43;
	for (int i = 1; i <= 43; i++)
		for (int j = 1; j <= 43; j++)
			if (i != j)
				s.insert({min(i, j), max(i, j)});	
	
	cout << res + s.size() << endl;//ans = 1204
} 

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

试题 B: 小球反弹

不会

试题 C: 好数

这题数据 1 e 7 1e7 1e7,暴力跑民间数据(92分,估分9分)

#include <bits/stdc++.h>

using namespace std;

bool check(int x) {
	vector<int> v;
	while (x) {
		v.push_back(x % 10);
		x /= 10;
	}
	for (int i = 0; i < v.size(); i++) {
		if (i % 2 == 0 && v[i] % 2 == 0) //奇数位 是偶数 
			return false;
		if (i % 2 != 0 && v[i] % 2 != 0) // 偶数位 是奇数 
			return false;
	}
	return true;
}

void solve() {
	int n;
	cin >> n;
	int res = 0;
	for (int i = 1; i <= n; i++) {
		if (check(i)) 
			res ++;
	}
	cout << res << endl;
}

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

试题 D: R 格式

考察高精度乘法、高精度加法,考场上直接暴力写的(民间测试52分,估分5分)

#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 1e5 + 7, inf = 0x3f3f3f3f, mod = 1e9 + 7;
// 浮点数 高精度乘法 ? 
void solve() {
	long double n, d;
	cin >> n >> d;
	long double res = 1.0 * d * (pow(2, n));
	//cout << fixed << setprecision(0) << (long double)(pow(2, n)) << endl;
	cout << fixed << setprecision(0) << res << endl;
}

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

正解:模拟高精度乘法,高精度加法

#include <bits/stdc++.h>
using namespace std;

int n; string d;
vector<int> A, B;

vector<int> mul(vector<int> &A, int b) {
    vector<int> C;
    int t = 0;
    for (int i = 0; i < A.size() || t; i++) {
        if (i < A.size()) t += A[i] * b;
        C.push_back(t % 10);
        t /= 10;
    }
    while (C.size() > 1 && C.back() == 0) C.pop_back();
    return C;
}

vector<int> mul(vector<int> &A, vector<int> &B) {
    vector<int> C(A.size() + B.size() + 7, 0);
    for (int i = 0; i < A.size(); i++) {
        for (int j = 0; j < B.size(); j++) {
            C[i + j] += A[i] * B[j];
        }
    }
    for (int i = 0; i + 1 < C.size(); i++) {
        C[i + 1] += C[i] / 10;
        C[i] %= 10;
    }
    while (C.size() > 1 && C.back() == 0) C.pop_back();
    reverse(C.begin(), C.end());
    return C;
}

vector<int> add(vector<int> &A, vector<int> &B) {
    if (A.size() < B.size()) return add(B, A);
    vector<int> C;
    int t = 0;
    for (int i = 0; i < A.size(); i++) {
        t += A[i];
        if (i < B.size()) t += B[i];
        C.push_back(t % 10);
        t /= 10;
    }
    if (t) C.push_back(t);
    return C;
}

int main() {
    cin >> n >> d;

    A.push_back(1);
    while (n--) A = mul(A, 2);

    //for (auto c : A) cout << c; cout << endl;

    int len = d.size() - d.find('.') - 1;
    reverse(d.begin(), d.end());
    for (auto c: d) {
        if (c != '.')
            B.push_back(c - '0');
    }
    //for (auto c : B) cout << c; cout << endl;
    auto res = mul(A, B);
    //for (auto c : res) cout << c; cout << endl;
    int last = -1;
    while (len--) last = res.back(), res.pop_back();
    if (last >= 5) {
        vector<int> base;
        base.push_back(1);
        reverse(res.begin(), res.end());
        res = add(res, base);
        reverse(res.begin(), res.end());
    }
    for (auto c: res) cout << c;
}

试题 E: 宝石组合

数论,赛场暴力写的民间测试过了一个点 ,估分2分

试题 F: 数字接龙

赛场调dfs调了很久调不出来,最后输出-1民间测试得分一半, 估分5分吧。正解dfs搜索,注意数学中的直角坐标方向与二维数组中的方向是不同的,按0,1,2…8的方向进行搜索,即可得到字典序最小的答案。最重要的问题是判路径是否交叉,可以拿一个dir数组记录当前遍历位置所走的方向(0~8),判断交叉共有四种情况即方向为1,3,5,7时,四种情况如下:
i == 1 && (dir[x - 1][y] == 3 || dir[x][y + 1] == 7)
i == 3 && (dir[x + 1][y] == 1 || dir[x][y + 1] == 5)
i == 5 && (dir[x][y - 1] == 3 || dir[x + 1][y] == 7)
i == 7 && (dir[x][y - 1] == 1 || dir[x - 1][y] == 5)
参考: 数字接龙-蓝桥杯

#include <bits/stdc++.h>

using namespace std;

typedef pair<int ,int> PII;
const int N = 10 + 7;
// int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
// int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; // 按照 0 1 2 3 ... 8的方向遍历
int n, k, g[N][N], dir[N][N], st[N][N];
vector<int> ans;

bool dfs(int x, int y, int cnt) {
	if (x == n - 1 && y == n - 1 && cnt == n * n) 
		return true;
	
	for (int i = 0; i < 8; i++) {
		int a = x + dx[i], b = y + dy[i];
		if (a < 0 || a >= n || b < 0 || b >= n || st[a][b]) continue;
		if ((g[a][b] != g[x][y] + 1 && g[x][y] >= 0 && g[x][y] < k - 1) || (g[a][b] != 0 && g[x][y] == k - 1)) continue;
		//检查是否路径交叉 
		if (i == 1 && (dir[x - 1][y] == 3 || dir[x][y + 1] == 7)) continue;
		if (i == 3 && (dir[x + 1][y] == 1 || dir[x][y + 1] == 5)) continue; 
        if (i == 5 && (dir[x][y - 1] == 3 || dir[x + 1][y] == 7)) continue; 
        if (i == 7 && (dir[x][y - 1] == 1 || dir[x - 1][y] == 5)) continue; 

		st[x][y] = 1, dir[x][y] = i;
		ans.push_back(i);
		if (dfs(a, b, cnt + 1)) return true;
		ans.pop_back();
		st[x][y] = 0, dir[x][y] = -1; //回溯
	}
	return false;
}

void solve() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> g[i][j];
			
	if (g[n - 1][n - 1] != k - 1 || g[0][0] != 0) {
		cout << -1; 
		return ;
	}	
	
	memset(dir, -1, sizeof dir);
	st[0][0] = 1;
	if (dfs(0, 0, 1)) {
		for (auto c : ans) cout << c;
	} else {
		cout << -1;
	}
}

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

试题 G: 爬山

思路:贪心 + 堆 , 每次用使用消除更多的方法,民间数据(92分,估分18分)

#include <bits/stdc++.h>

#define x first
#define y second
#define int long long

using namespace std;

typedef pair<int ,int> PII;
const int N = 1e5 + 7, inf = 0x3f3f3f3f, mod = 1e9 + 7;
int n, k, q, p, x;

//贪心 堆 

void solve() {
	cin >> n >> p >> q;
	priority_queue<int, vector<int>> heap;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		heap.push(x);
	}
	while (!heap.empty()) {
		auto t = heap.top();
		
		if (p <= 0 && q <= 0) break;
		
		if (p > 0 && q > 0) {
			heap.pop();
			int det1 = abs(t - floor(sqrt(t))), det2 = t / 2;
			if (det1 >= det2) 
				heap.push(floor(sqrt(t))), p --;
			else
				heap.push(t / 2), q --;
		}
		else if (p > 0 && q <= 0) {
			heap.pop();
			heap.push(floor(sqrt(t))), p --;
		} else if (p <= 0 && q > 0) {
			heap.pop();
			heap.push(t / 2), q --;
		} 
	}
	int res = 0;
	while (!heap.empty()) {
		res += heap.top();
		//cout << heap.top() << endl;
		heap.pop();
	}
	cout << res << endl;
}

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

试题 H: 拔河

没读懂题,前缀和枚举思路,民间测试10分,估分2分。
题意是任意选出两队,不要求选完,考场上误以为要选完,直接枚举中点前缀和处理了。

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

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

相关文章

深度学习之基于YOLOv5烟花燃放智能检测系统

欢迎大家点赞、收藏、关注、评论啦 &#xff0c;由于篇幅有限&#xff0c;只展示了部分核心代码。 文章目录 一项目简介 二、功能三、系统四. 总结 一项目简介 一、项目背景与意义 在庆祝和特殊节日中&#xff0c;烟花燃放作为传统的庆祝方式之一&#xff0c;深受人们的喜爱。…

ChatGPT的AI“记忆”可以记住付费客户的偏好

通过记住有关 ChatGPT Plus 订阅者的详细信息&#xff0c;OpenAI 的聊天机器人添加了更多个人助理风格的功能 OpenAI 在今年二月宣布了 “记忆 ”功能&#xff0c;该功能允许 ChatGPT 更永久地存储查询、提示和其他自定义功能。当时&#xff0c;只有 “一小部分 ”用户可以使用…

ChatGPT 网络安全秘籍(一)

原文&#xff1a;zh.annas-archive.org/md5/6b2705e0d6d24d8c113752f67b42d7d8 译者&#xff1a;飞龙 协议&#xff1a;CC BY-NC-SA 4.0 前言 在不断发展的网络安全领域中&#xff0c;由 OpenAI 推出的 ChatGPT 所代表的生成式人工智能和大型语言模型&#xff08;LLMs&#xf…

Mybatis.net + Mysql

项目文件结构 NuGet下载Mybatis.net相关包&#xff1a;IBatisNet 安装完成后&#xff0c;会显示在&#xff0c;在已安装页面。同时&#xff0c;在管理器中的引用列表中&#xff0c;会多出来两个引用文件 IBatisNet.CommonIBatisNet.DataMapper 安装 Mysql.data。 注意&#xff…

深入理解正则表达式:从入门到精通

title: 深入理解正则表达式&#xff1a;从入门到精通 date: 2024/4/30 18:37:21 updated: 2024/4/30 18:37:21 tags: 正则Python文本分析日志挖掘数据清洗模式匹配工具推荐 第一章&#xff1a;正则表达式入门 介绍正则表达式的基本概念和语法 正则表达式是一种用于描述字符串…

Android 音视频播放器 Demo(二)—— 音频解码与音视频同步

音视频编解码系列目录&#xff1a; Android 音视频基础知识 Android 音视频播放器 Demo&#xff08;一&#xff09;—— 视频解码与渲染 Android 音视频播放器 Demo&#xff08;二&#xff09;—— 音频解码与音视频同步 RTMP 直播推流 Demo&#xff08;一&#xff09;—— 项目…

使 Elasticsearch 和 Lucene 成为最佳向量数据库:速度提高 8 倍,效率提高 32 倍

作者&#xff1a;来自 Elastic Mayya Sharipova, Benjamin Trent, Jim Ferenczi Elasticsearch 和 Lucene 成绩单&#xff1a;值得注意的速度和效率投资 我们 Elastic 的使命是将 Apache Lucene 打造成最佳的向量数据库&#xff0c;并继续提升 Elasticsearch 作为搜索和 RAG&a…

Jenkins自动化搭建记录

每一份努力都是有一份期盼&#xff0c;每一份付出都是为了有更多的收获。 本文记录一次搭建Jenkins自动参数化打包APK的实现过程和碰到的问题&#xff0c;实现了在Windows和Mac系统下的自动化打包流程。 因为Jenkins的安装过程在网上的教程很多&#xff0c;这里就不在赘述。 …

使用 LlamaIndex 和 Llama 2-Chat 构建知识驱动的对话应用程序

文章目录 使用 LlamaIndex 和 Llama 2-Chat 构建知识驱动的对话应用程序Llama 2-70B-聊天LlamaIndex 解决方案概述先决条件使用 SageMaker JumpStart 部署 GPT-J 嵌入模型使用 SageMaker Python SDK 进行部署在 SageMaker Studio 中使用 SageMaker JumpStart 进行部署使用 Sage…

Dashboard 介绍

Dashboard 介绍 一、K8S Dashboard简介 简单的说&#xff0c;K8S Dashboard是官方的一个基于WEB的用户界面&#xff0c;专门用来管理K8S集群&#xff0c;并可展示集群的状态。K8S集群安装好后默认没有包含Dashboard&#xff0c;我们需要额外创建它 二、RABC简介 还是那句话&a…

关于下载上传的sheetjs

一、背景 需要讲后端返回来的表格数据通过前端设置导出其中某些字段&#xff0c;而且得是xlsx格式的。 那就考虑使用控件SheetJS。如果是几年前&#xff0c;一般来说&#xff0c;保存excel的文件都是后端去处理&#xff0c;处理完成给前端一个接口&#xff0c;前端调用了打开…

SQLite的扩展函数Carray()表值函数(三十八)

返回&#xff1a;SQLite—系列文章目录 上一篇:SQLite如何处理CSV 虚拟表 下一篇&#xff1a;SQLite—系列文章目录 ​ 1. 概述 Carray()是一个具有单列的表值函数(名为 “value”)和零行或多行。 carray() 中每一行的“值”取自 C 语言数组 由应用程序通过参数绑定提…

如何进行面向对象分析、面向对象设计和面向对象编程

目录 1.引言 2.案例介绍和难点剖析 3.如何进行面向对象分析 4.如何进行面向对象设计 5.如何进行面向对象编程 6.总结 1.引言 面向对象分析(OOA)、面向对象设计(00D)和面向对象编程(OOP)是面向对象开发的3个主要环节。 在以往的工作中&#xff0c;作者发现&#xff0c;很多…

JavaScript原型链深度剖析

目录 前言 一、原型链 1.原型链的主要组成 原型&#xff08;Prototype&#xff09; 构造函数&#xff08;Constructor&#xff09; 实例&#xff08;Instance&#xff09; 2.原型链的工作原理 前言 在JavaScript的世界中&#xff0c;原型链&#xff08;Prototype Chain&…

Amazon云计算AWS之[4]非关系型数据库服务SimpleDB和DynamoDB

文章目录 简介非关系型VS关系数据库SimpleDB域条目属性值SimpleDB的使用 DynamoDBSimpleDB VS DynamoDB 简介 非关系型数据库服务主要用于存储结构化的数据&#xff0c;并为这些数据提供查找、删除等基本的数据库功能。AWS中提供的非关系型数据库主要包括SimpleDB和DynamoDB …

聚醚醚酮(Polyether Ether Ketone)PEEK在粘接使用时可以使用UV胶水吗?要注意哪些事项?

一般情况下&#xff0c;聚醚醚酮&#xff08;Polyether Ether Ketone&#xff0c;PEEK&#xff09;是一种难以黏附的高性能工程塑料&#xff0c;而UV胶水通常不是与PEEK进行粘接的首选方法。PEEK表面的化学性质和高温性能使得它对常规胶水的附着性较低。然而&#xff0c;有一些…

(成品论文22页)24深圳杯数学建模A题1-4问完整代码+参考论文重磅更新!!!!

论文如下&#xff1a; 基于三球定位的多个火箭残骸的准确定位 针对问题一&#xff1a;为了进行单个残骸的精确定位&#xff0c;确定单个火箭残骸发生音爆 时的精确位置和时间&#xff0c;本文基于三球定位模型&#xff0c;考虑到解的存在性和唯一性&#xff0c; 选取了四个监测…

用HTML5实现播放gif文件

用HTML5实现播放gif文件 在HTML5中&#xff0c;你可以使用<img>标签来播放GIF文件。GIF文件本质上是一种图像格式&#xff0c;它支持动画效果&#xff0c;因此当在网页上加载时&#xff0c;它会自动播放动画。先看一个简单的示例&#xff1a; <!DOCTYPE html> &l…

清华同方电脑文件删除怎么恢复

在日常使用清华同方电脑的过程中&#xff0c;我们难免会遇到误删重要文件的情况。文件丢失不仅可能导致数据损失&#xff0c;还可能影响到我们的工作、学习甚至是生活。那么&#xff0c;当在清华同方电脑上删除了重要文件后&#xff0c;我们应该如何恢复呢&#xff1f;本文将为…

Linux服务器安全基础 - 查看入侵痕迹

1. 常见系统日志 /var/log/cron 记录了系统定时任务相关的日志 /var/log/dmesg 记录了系统在开机时内核自检的信息&#xff0c;也可以使用dmesg命令直接查看内核自检信息 /var/log/secure:记录登录系统存取数据的文件;例如:pop3,ssh,telnet,ftp等都会记录在此. /var/log/btmp:记…
最新文章