快速排序 题解

C++题解 快速排序 题目描述 给定你一个长度为 n 的整数数列。 请你使用快速排序对这个数列按照从小到大进行排序。 并将排好序的数列按顺序输出。 输入格式 输入共两行,第一行包含整数 n。 第二行包含 n 个整数(所有整数均在 1∼109 范围内),表示整个数列。 输出格式 输出共一行,包含 n 个整数,表示排好序的数列。 数据范围 1≤n≤100000 输入样例: 5 3 1 2 4 5 输出样例: 1 2 3 4 5 思路 对于快速排序,我们选定一个基准数base,为了方便,可以取数组中间的数base = a[ l 阅读详情

排序

Time Limit: 1000ms   Memory limit: 32678K  有疑问?点这里^_^

题目描述

    给你N(N<=100)个数,请你按照从小到大的顺序输出。

输入

    输入数据第一行是一个正整数N,第二行有N个整数。

输出

    输出一行,从小到大输出这N个数,中间用空格隔开。

示例输入

51 4 3 2 5

示例输出

1 2 3 4 5

快排心得: 快速排序核心思想就是递归,每次都选择a[high]当做标杆,大于的放右边,小于的放左边,依次递归下去。。。   (坚信努力会有成果!每天一道算法,加油!)

代码:
#include <iostream>

using namespace std;
int a[100010];
int parti(int a[],int low,int high)
{
    int i=-1,j=0;
&nb
题解:AcWing 785 快速排序 的高效排序算法,通过选择一个基准元素将序列划分为两个子序列,再递归排序子序列。的整数序列,需要将其按从小到大排序。请你使用快速排序对这个数列按照从小到大进行排序。并将排好序的数列按顺序输出。个整数,表示排好序的数列。输入共两行,第一行包含整数。范围内),表示整个数列。个整数(所有整数均在。 阅读详情

相关推荐

题解:学而思编程 快速排序

等知名刷题平台精心挑选而来,并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构,旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。快速排序是信息学竞赛的必备算法之一。对于快速排序不是很了解的同学可以自行上网查询相关资料,掌握后独立完成。(C++ 选手请不要试图使用。个数从小到大输出,数之间空格隔开,行末换行且无空格。一遍过,但是你并没有掌握快速排序算法的精髓。,为你需要进行排序的数,数据保证了。利用快速排序算法将读入的。个数从小到大排序后输出。

团爸讲算法 78

R语言批量抓取TCMSP中药靶点基因:告别手工复制粘贴

网络药理学研究中,中药靶点数据整理常依赖TCMSP等数据库,但手工复制粘贴效率低且易错。通过R语言网络抓取技术,可自动化获取TCMSP中的成分与靶点信息,提升数据收集的准确性和可重复性。该方法基于HTTP请求与HTML解析原理,结合随机延时控制访问频率,适用于复方中药机制研究、多数据库交叉验证等场景。本文分享的脚本方案,帮助研究者高效构建成分-靶点网络,为后续富集分析和网络构建奠定可靠数据基础。

weixin_33563728的博客 344

告别串口助手!手把手教你用Matlab直接读取STM32的传感器数据(附完整代码)

本文详细介绍了如何利用Matlab直接与STM32进行串口通信,实现传感器数据的实时采集与分析。通过完整的代码示例和系统架构设计,帮助开发者告别传统的串口助手工具链,打造高效、自动化的数据采集系统。文章涵盖了从硬件配置、通信协议设计到Matlab数据处理与可视化的全流程,特别适合嵌入式开发与数据分析结合的实践场景。

weixin_42629671的博客 432

自动驾驶仿真工具链集成:ECU TEST与VTD、VERISTAND的深度配置指南

本文详细介绍了自动驾驶仿真测试中ECU TEST、VTD与VERISTAND三大核心工具的深度集成与连接配置方法。通过解析工具链的角色分工,提供从单机到分布式部署的实战指南,并重点阐述了Test Bench Configuration与Test Configuration的关键参数设置、SSH免密登录配置,以及在线与离线工作模式的切换技巧,旨在帮助测试工程师高效构建稳定、自动化的硬件在环测试环境。

wind6的博客 802

手把手教你解决Realsense D455在ROS下IMU数据不输出的问题(附固件降级指南)

本文详细解析了Realsense D455在ROS环境下IMU数据不输出的问题,提供了固件降级和ROS配置的完整解决方案。通过版本兼容性分析和实战操作指南,帮助开发者快速恢复IMU数据流,优化机器人开发体验。

weixin_42531494的博客 381

Ubuntu1804 关于ubuntu18.04下载软件仓库信息失败,请检查网络连接 的解决方案

今天电脑在更换软件源的时候遇到了这个问题。出现了如上图所示的错误信息。 尝试了各家CSDN的博客之后,发现方法大同小异,均无法解决。 方法大多都是要求更换软件源,如下所示: 打开“Ubuntu软件中心”-->点击“编辑”-->点击“软件源”-->在Ubuntu软件界面,“下载自”默认是“中国的服务器”,改为“主服务器”试试 2.打开更新管理器-》设置-》选择站点-》...

weixin_43729409的博客 1万+

Vue3 - 强力解决前端下载二进制流pdf文件、下载成功后打开空白问题解决,或者获取PDF文件流,将blob对象转换成下载链接打开后一片空白(无论是否使用pdf插件下载,还是原生方法下载都完美解决)

vue3前端下载二进制流pdf文件,下载成功,打开空白问题解决,js下载PDF文件流,打开空白问题,VUE3 h5中的文件流下载和指定的url下载总结(解决下载后的pdf打开空白情况)pdfjs打开文件流空白,解决pdf文件流,预览全是空白页,pdf文件流,下载正常,但是预览全是空白页,前端JS获取PDF文件流,将blob对象转换成下载链接打开后一篇空白的问题,前端文件流下载后文件空白,前端下载文件流PDF文件显示空白 或 无法打开,在线预览PDF文件打不开白屏怎么办,前端axios请求二进制数据流转换生成

🏆 前端领域优质创作者 4626

2025年09月中国电子学会青少年软件编程(Python)等级考试试卷(三级)答案 + 解析

2025年09月中国电子学会青少年软件编程(Python)等级考试试卷(三级)答案 + 解析

伶俐角少儿编程 529

华为OD机考双机位C卷 - 简单的解压缩算法 (Java & Python & JS & GO & C++ & C)

华为OD机考双机位C卷 - 简单的解压缩算法 , 提供Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。

算法大师! 136

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

深度学习工具包 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")

上一篇: Docker之常用命令
下一篇: 二分查找 题解
SDUT_wdc
博客等级 码龄11年 47粉丝 60原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值