2021 CSP-J 题解

CSP-J 2021 入门组/普及组 文章目录整体难度分析T1 分糖果T1分析T2 插入排序T2分析1. 常规解法2. 黑科技 pb_dsT3 网络连接T3分析T4 小熊的果篮T4分析 整体难度分析 整体来说这一场 CSP 的比赛难度并不高,四道题基本都是模拟题,至少有 310310310 分是纯暴力可以直接获得的 但是对代码量和细节问题的处理要求相对高一些,在 OI 的比赛模式中,很容易因为踩了一个坑导致分数非常低 整体来说难度不高,题目类型更加偏向于 CF 类的简单题 T1 分糖果 【题目背景】 红太阳幼儿园的小朋友们开始分糖果啦! 【题目 阅读详情

[CSP-J 2021] 分糖果

本题考查了一个数学的思路,没有什么难度。

一句话题意: 在区间[L, R]内找到一个数字x,使得x%n 最大。

分析:

  1. 从对n的余数的分布来考虑,余数总是: 0, 1, 2, …, n-1, 0, 1, 2, …, n-1, 0, …循环分布。并且每个为0的位置都是n的倍数。
  2. 因此可以知道,如果[L, R] 是跨越了一个0的区间,则一定存在余数为n-1。如果没有跨过,则余数在[L, R] 内递增分布。
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n, m;

int main(){
   
   
    
        int l, r;
        cin >> n >> l >> r;

        if(r / n > l / n) {
   
   
            cout << n-1 << endl;
        } else {
   
   
            cout << r % n << endl;
        }
    return 0;
}

[CSP-J 2021] 插入排序

题目的关键在于,对于数组的改动仅有5000次。

  1. 因此对于每次改动,可以允许我们做一个O(n) 的维护操作。
  2. 对于每个查询,我们需要O(1)得到结果。

以下代码中:

  • id[i] 表示现在第i个数字原来的位置。
  • vis[i] 表示原第i个数字现在的位置。
  • b[] 用于数据排序。
  • a[] 用于存储原的数据。

36 分(n3n^3n3 大模拟)

每次按照题目的伪代码翻译一下,写成一个mysort函数,然后每次修改之后都调用一次,得到一个排序后结果。记录每个数字现在的位置即可。


ll a[MAXN], b[MAXN], id[MAXN], vis[MAXN];
int n, m;

// 复杂度 n^2
void mysort() {
   
   
    memcpy(b, a, sizeof(a));
    for(int i = 1; i <= n; i++) vis[i] = id[i] = i;
    for(int i = 1; i <= n; i++) {
   
   
        for(int j = i; j >= 2; j--) {
   
   
            if(b[j] < b[j-1]) {
   
   
                swap(b[j], b[j-1]);
                vis[id[j]] = j-1;
                vis[id[j-1]] = j;
                swap(id[j], id[j-1]);
            }
        }
    }
}

void solve_1() {
   
   
    mysort();
    while(m--) {
   
   
        int ty;
        cin >> ty;
        if(ty == 1) {
   
   
            int x, v;
            cin >> x >> v;
            a[x] = v;
            mysort();
        } else if(ty == 2) {
   
   
            int x;
            cin >> x;
            cout << vis[x] << endl;
        }
    }
}


52 分(使用sort优化排序)

针对排序,我们可以使用sort排序,但是伴随着相同数字的相对位置的问题,因此我们需要知道每个数字在相同数字之间的相对位置。这一点可以通过预处理得到。

map<int, int> M;  // 一个桶,用于存数字出现次数。
void handle_2() {
   
   
    M.clear();
    memcpy(b, a, sizeof(a)
CSP-J 2021解题报告 好好复习初赛,我压线过的 瞎搞的封面 1.分糖果 一般来说T1都不会太难,其实他还是不是很难 我太蒻了,考场半小时才想出来 咳咳,一看数据范围有有 10^9,一看就不是用暴力做的。 假如有n个小朋友(包括你),你搬了k块糖果,那么你最终得到的奖励就是 k mod n 块糖果。也就是说,假如你最少搬l块糖果,最多搬k块糖果,你如果要得到最多的奖励,就要在l到r之间选一个数,使得这个数模n的值最大。 那么最优的情况下会剩 n - 1 块糖果,当然,样例 2告诉我们,有时候我们没法这... 阅读详情

相关推荐

csp-j2021题解

)尽可能多;因此你需要写一个程序,依次输入。

Hiworldgg的博客 1393

[题解] [CSP-J 2021] c++ 分糖果

然后,将算出来的数量与当前最大值作比较,如果比最大值大,说明搬回i颗糖时,能拿到的作为奖励的糖目前最大,那么就将最大值更新。注意:最大值一开始要设为0,写代码的时候能写多简单就写多简单,不然会TLE。再按照上面的公式,计算当搬回来i颗时,可以得到多少颗糖果作为奖励。就可以发现:任意一个数 = k / n(k和n都是整型数)搬糖果的奖励的糖果数量 = k - n * (k / n)先写一个for循环(循环变量为i)遍历l到r之间所有的数字。搬糖果的奖励的糖果数量 = k - n * 任意一个数。

FYCCCTA的博客 1027

2021 CSP-J题解

CSP-J 2021 详解

EXGZC的博客 1250

新鲜出炉的 CSP-J 2021 复赛题目 题解

2021普及组复赛 代码量大点,难度一般。 T1 P7909 [CSP-J 2021] 分糖果 最简单容易想到的思路,应该就是枚举[L,R]范围内的每一个数字 %n 的结果,保留最大结果,如下所示。 //分糖果 #include<bits/stdc++.h> using namespace std; int main(){ int n,L,MX=0; cin>>n>>L>>R; for(int i=L;i<=R;i++) { MX=max(

qq_23109971的博客 7762

[CSP-J 2021]比赛题解

原序列为 1,1,4,5,6,71,1,4,5,6,7,修改为 1,1,9,5,6,71,1,9,5,6,7。同样的,我们可以维护一个有序数列,并记录原下标与先下标之间的关系(用数组记录),每次修改后更新这种关系。我们可以从前往后冒泡,再次维持了数列的有序。这样的操作是 \mathcal{O}(n)O(n) 的。这样,修改操作是 O(n) 的,查询是 O(1) 的。

weixin_56550385的博客 878

从零搭建自动驾驶仿真环境:我的Nuplan-devkit实战笔记(含PyCharm配置技巧)

本文详细记录了从零搭建Nuplan-devkit自动驾驶仿真环境的完整流程,包括conda环境配置、pip版本控制、PyCharm专业版集成等关键步骤。特别针对Ubuntu系统下的依赖管理、数据目录优化和性能调优提供了实用技巧,帮助开发者高效构建稳定的自动驾驶仿真开发环境。

weixin_30505225的博客 479

基于STM32F334C8T6的四开关Buck-Boost双向DC-DC电源设计与实现(附源码、仿真与计算书)

本文详细介绍了基于STM32F334C8T6的四开关Buck-Boost双向DC-DC电源设计方案。该设计利用STM32的高分辨率定时器(HRTIM)实现精确PWM控制,支持Buck、Boost和Buck-Boost三种工作模式自动切换,具备双向能量流动能力。通过PSIM仿真和Mathcad计算书进行参数优化,实测效率达95.8%,适用于新能源系统和电池管理等场景。

www00的博客 525

别再被SpringerLink虐了!手把手教你搞定LaTeX源文件提交(附正确文件顺序和类型选择)

本文详细解析了SpringerLink投稿系统中LaTeX源文件提交的常见问题与解决方案,包括文件打包、类型选择和顺序排列等关键步骤。通过实战经验,帮助科研人员避开隐形陷阱,一次性完成LaTeX提交,提升投稿效率。特别针对`.bst`和`.cls`文件的正确处理提供了专业指导。

weixin_42522964的博客 444

基于libVLC的视频播放器之四:直接使用libVLC

一.效果 播放本地文件 播放网络url:rtsp://3.84.6.190/vod/mp4:BigBuckBunny_115k.mov 二.实现 既然有VLC-Qt,为什么还要直接调用libVLC呢,因为直接调用会加深对整个播放流程的理解,方便后面修改VLC-Qt源码。 注意事项: 1.编译报错:error C2065: “libvlc_media_read_cb”: 未声明的标识符。修改如下: 2.libvlc_new(0, nullptr)返回null 将plugins

草上爬的博客 5048

多模态轨迹预测:行人、车辆的交互式推理

多模态轨迹预测:行人、车辆的交互式推理 ,人工智能,计算机视觉,大模型,AI,本文围绕多模态轨迹预测中行人与车辆的交互式推理展开,介绍了其定义,即综合多种信息预测交通参与者未来多种轨迹。涵盖基础概念如轨迹表示、模态、交互关系,技术框架包括数据处理、特征提取、预测模型(物理、机器学习、深度学习模型等)及结果评估。还探讨了交互式推理方法、面临的不确定性处理等挑战、应用场景、未来发展方向、相关工具及实际案例,展现了该技术在智能交通等领域的重要性与发展潜力。​

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 14万+

Claude Code 处理长任务 + Cursor 专注交互:双栈协作的 3 种分工场景与响应提速 35% 实测

揭示 Claude Code 与 Cursor 在 AI 编程中的本质分工:Claude Code 作为离线式架构师处理跨文件、带约束的长链路重构(如单体拆微服务),Cursor 作为现场交互工程师专注秒级局部编辑;提出按任务切片动态切换的三种工程化协作场景,并给出结构化上下文构建、约束型 Prom

weixin_28728443的博客 123

Python全栈项目--手机语音远程控制智能家居系统(含嵌入式控制)

摘要:本项目实现了一个基于Python全栈的智能家居语音控制系统,支持手机端语音指令控制家居设备。系统采用FastAPI后端+Vue3前端的架构,集成Web Speech API实现语音识别,通过嵌入式设备(如ESP32)执行硬件控制。功能包括用户认证、设备管理、场景联动、指令解析和日志记录,支持HTTP轮询和直推两种命令下发模式。项目涵盖物联网全链路开发,适用于课程设计或毕业设计原型开发。

exlink2012的专栏 877

深度解析大众点评反爬机制:构建高可用店铺评论采集系统(2026最新实战)

在中文互联网数据采集领域,大众点评(现归属美团)始终占据着特殊地位。其丰富的UGC(用户生成内容)包含了超过2亿条真实店铺评论、数百万家商户的详细POI信息以及用户行为数据,对商业分析、口碑监测、本地生活趋势研究具有不可替代的价值。然而,大众点评的安全团队投入了顶级资源构建反爬系统——从请求签名、行为验证到设备指纹,其防御强度甚至超过多数电商平台。本文将完整呈现一套2026年依然有效的技术方案,包括破解核心参数_token、动态代理池维护、无头浏览器指纹伪装等,最终产出一个生产级采集框架。目录。

2201_76125261的博客 811

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

上一篇: Codeforces Round #749 (Div. 1 + Div. 2)
下一篇: 2021 CSP-S2 题解(完整版)
AC-Panda
博客等级 码龄5年 1736粉丝 191原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值