爆刷PAT(甲级)——之【1101】 Quick Sort (25 分)——简单思维

PAT甲级——1101 Quick Sort (快速排序) 1101Quick Sort(25分) There is a classical process namedpartitionin the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the p... 阅读详情

题意:给一个无序的正数数组(各数不同),找出,所有左边的数小于它,所有右边的数大于它,的数。输出符合条件的数,以及其个数。

思路:一下子就可以想到,所有左边的数小于它,那就是左边最大的数都比它小。

所有右边的数都大于它,那就是右边最小的数都比它大。即可。

所以什么操作都不需要,直接两个O(N),建立两个数组 l[i] 和 r[i] ,表示 i 下标位置左边最大的数和右边最小的数,扫一遍就建立好了。

然后每个点判断一边,如果元素比它左边一格的 l[i-1]都大,那就符合第一个条件;如果元素比它右边一格的 r[i+1] 都大,就符合第二个条件。都符合就加入vector最后排个序输出即可。

 

坑点:

两个坑爹之处——N小于等于10e5,数组别开小了;答案可能为0,但是输出还要输出一个'\n',不然会PLE.

Code:

#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define inf 100009
#define INF 0x3f3f3f3f
#define loop(x,y,z) for(x=y;x<z;x++)

int n;
int e[inf];
int l[inf];//find max
int r[inf];//find min
vector<int>ans;//the ans

int main()
{
    int i;
    cin>>n;
    for(i=1;i<=n;i++)scanf("%d",&e[i]);
    l[0]=0;
    r[n+1]=INF;
    for(i=1;i<=n;i++)l[i]=max(l[i-1],e[i]);
    for(i=n;i>0;i--)r[i]=min(r[i+1],e[i]);
    //判断
    for(i=1;i<=n;i++)
        if(e[i]>l[i-1]&&e[i]<r[i+1])
            ans.push_back(e[i]);
    sort(ans.begin(),ans.end());
    printf("%d\n",ans.size());
    if(!ans.size()){printf("\n");return 0;}//本题目最骚的地方
    for(i=0;i<ans.size()-1;i++)printf("%d ",ans[i]);
    printf("%d\n",ans[i]);
    return 0;
}

 

Foobar2000 1.2.3 Asion中文增强版 高级音频播放器 Foobar2000 是一个 Windows 平台下的高级音频播放器,包含完全支持 unicode 及支持播放增益的高级标签功能。Foobar2000 V1.2.1 Final 中文版由Asion汉化,集成了APE解码器、DTS解码器、TTA解码器、TAK解码器、SACD解码器、歌词秀3(歌词插件)、播放统计信息插件。 Foobar2000特色: * 支持的音频格式: MP3, MP4, AAC, CD Audio, WMA, Vorbis, FLAC, WavPack, WAV, AIFF, Musepack, Speex, AU, SND, 通 过第三方插件将支持更多的格式. * 完全支持 Unicode * 轻松定制用户界面布局 * 高级标签功能 * 可以使用转换器组件对所有支持的格式转换编码格式 * 支持播放增益 * 可自定义快捷键 * 开放的组件体系结构允许第三方开发者来扩展播放器的功能. 汉化版加入了以下插件(均为可选安装): A版:APE 解码器 B版: APE 解码器 DTS 解码器 TTA 解码器 TAK 解码器 SACD 解码器 歌词秀3 播放统计信息 立即下载

相关推荐

【Docker】如何让docker容器正常使用nvidia显卡

描述了如何在docker容器中使用英伟达显卡的过程和问题解决方法。

NameLoadingFailed的博客 8372

PAT甲级1101 Quick Sort (25 分)题解

\quad这是一道逻辑题,给了快排的背景。题目大意是给你一个数字序列,找出这个序列里面有多少个数满足两个条件: 它左边的数都小于它 它右边的数都大于它 \quad我们可以暴力求解,时间复杂度为O(n2)O(n^2)O(n2),肯定会超时。正解是将序列存入两个数组a和b,对a排序,比如a={1,2,3,4,5},b={1,3,2,4,5},那么遍历b,若满足下列三个条件则该元素为正确解答的一部...

qq_40438165的博客 1549

三角洲行动交易行自动化脚本

DFMarketBot - 三角洲行动自动交易助手 DFMarketBot是一款专为三角洲行动游戏设计的交易行自动化工具,通过OCR识别和鼠标模拟实现自动补卡、补子弹功能。项目采用Python开发,支持Windows平台,主要功能包括: 自动检测并购买指定物品(房卡/子弹) 价格监控与智能购买(低于设定价格自动下单) 自定义购买数量与次数限制 支持窗口/无窗口两种游戏模式 使用前需安装Tesseract OCR引擎并配置游戏为1920*1080分辨率。通过JSON文件可灵活配置监控物品清单、理想价格和购买策

愤怒的阿木木的博客 3万+

1101 Quick Sort

1101 Quick Sort

weixin_48448010的博客 162

MATLAB实战:5步搞定GNSS单点定位解算(附完整代码)

本文提供了一份基于MATLAB的GNSS单点定位实战指南。通过5个核心步骤,详细讲解了如何从卫星坐标和伪距观测值出发,利用最小二乘迭代算法,构建并实现一个完整的单点定位解算器。文章附有完整代码,并涵盖精度评估与结果分析,适合GNSS初学者和MATLAB用户快速上手实践。

a2b3c4d5e的博客 250

避坑指南:雅特力AT32F403A在Keil5中的V2库配置常见问题解析

本文详细解析了国产MCU雅特力AT32F403A在Keil5中配置V2库的常见问题,包括工程创建、库文件配置、编译错误和外设设置等关键环节。针对项目文件夹结构混乱、芯片型号选择错误、头文件路径设置不当等典型问题提供实用解决方案,帮助开发者高效避坑,提升开发效率。

weixin_30335575的博客 375

1101. Quick Sort

这道题想找到一组数据中满足,左边的数字都小于它,右边的数字都大于它的数字。 最暴力的方法n^2会超时 这道题的Quick Sort实际上已经提示我们了,这道题的重点在于发现符合题目条件的数字在sort之后的位置是相同的,这一点回想quick sort过程就很容易验证,并且保证数组中的数字要大于前面数字的最大值,就会满足题意,具体代码如下:#include<iostream> #include<v

写代码的柯长的博客 326

科研神器: 用Gemini 3

Edge藏了个科研开挂神器!免TZ/免谷歌账号用Gemini 3,1分钟上手(附保姆级教程) 做科研查文献、理数据总卡壳?想蹭Gemini 3的AI能力,却被“谷歌账号+TZ+节点筛选”三连劝退? 现在不用折腾了!Edge浏览器里装个插件,直接把Gemini 3揣进口袋——**免翻墙、免谷歌账号、国内直接用**,分分钟让你的科研效率翻三倍,导师都得问你“偷偷开了啥挂”!

ZhangJiqun&191cm&85kg 1159

1101 Quick Sort (25分)[逻辑][快速排序]

By Jalan 文章目录**By Jalan**知识工具需求数学数据结构和算法语言题干输入条件输出条件坑点例子例1输入输出题解第一次思路预期时间复杂度编写用时代码CPP运行用时结尾 知识工具需求 数学 数据结构和算法 语言 题干 快速排序有分类这个步骤,就是选一个数把比他小的放一边大的放另一边. 现在看看有没有这些数 输入条件 N个数<=10^5 每个数不会大于10^9 输出条件 输出左边都比它小右边都比它大的数的个数和数,末尾没空格. 坑点 这题有一个地方我真的没懂,输出完还要打印个换行,要不会有

JalanChao的博客 346

Python基础语法与最佳实践【python基础篇】

本文全面介绍了Python基础语法与最佳实践,涵盖变量与数据类型、控制流、函数、模块与包等核心概念。通过实际代码示例展示了条件语句、循环结构、函数定义及模块导入的基本用法。在最佳实践部分,重点讲解了PEP 8代码风格规范、异常处理技巧、列表推导式、上下文管理器、文档字符串编写以及enumerate和zip的高效使用。这些内容既适合Python初学者掌握基础语法,也能帮助有经验的开发者编写更规范、高效、可维护的代码。文章强调遵循Python官方推荐实践,通过合理运用语言特性提升代码质量。

博客 1975

元宇宙通证- 九、IT/ICT发展史全景长图

九、IT/ICT发展史全景长图 (一)综述 IT是Information Technology的缩写,意为”信息技术“,包含现代计算机、网络、通信等信息领域技术。自1844年人类历史上发出来第一份电报,实现了信息的长图传输,信息技术发展的历史大幕随之拉开。信息技术的普遍应用,是进入信息社会的标志。 IT技术最早发源于半导体,然后发展处计算机、通信网和互联网,进而演进到现在的AI、XR、计算机、大数据、物联网、工业互联网、区块链、量子计算等。 有人说元宇宙是下一代互联网,有人说元宇宙是互联网的终极形态。 我们

沧海之巅的专栏 1万+

PAT甲级1101 Quick Sort:[C++题解]DP、快速排序划分个数、快排

刷题

阿正的梦工坊 579

30.Labview如何读懂别人程序、修改程序?

之前写过一次教大家的文章,这次教大家如何学习别人的程序,和如何搭建一套适合自己的程序框架。这里事先说明一下:要想搭好程序框架,一定要先把自己的系统,逻辑是什么!这非常重要,是决定你程序的关键因素。废话不多扯,直接说重点。

关注我,更多技术问题欢迎私聊~ 2446

1101 Quick Sort——PAT甲级

【代码】1101 Quick Sort——PAT甲级。

flyidj的博客 1754

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

【PAT甲级 - C++题解】1101 Quick Sort

📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!

Newin2020的博客 604

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

[PAT B1045/A1101]Quick Sort

[PAT B1045/A1101]Quick Sort 本题是PAT乙级1045题和甲级1101题,这里先放英文原题,要做乙级题的同学可以直接看后面的中文原题 题目描述 1101 Quick Sort (25 分)There is a classical process named partition in the famous quick sort algorithm. In this proc...

欢迎来到我的编程小屋 602

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

【PAT甲级】1101 Quick Sort (25分)

解题过程的小记录,如有错误欢迎指出。 难度:一星(在做完1012后弄懂排序规则后此题并不难) 小导航~题目分析注意点我的解题过程思路bug代码dalao的代码借鉴点 题目分析 注意点 我的解题过程 思路 bug 代码 dalao的代码 全部代码因版权原因不放出来,大家可以自行去柳神博客购买或者参考晴神的上机笔记~ 借鉴点 ...

SpicyChicken的自我修养 5115

PAT甲级1101 Quick Sort (25 分)

1101Quick Sort(25分) There is a classical process namedpartitionin the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the p...

Dexter 275

1101 Quick Sort (25 分)

1101 Quick Sort (25 分) There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its left and those larger than the pivo

Tropine的博客 190

PAT 甲级 1101  Quick Sort

1101 Quick Sort (25 point(s)) There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less tha...

漫浸天空的雨色的备忘录~ 607

甲级PAT 1101 Quick Sort (25 分)

1101 Quick Sort (25 分) There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the p...

Joyceyang_999的博客 258

PAT甲级1101、Quick Sort

这个题目一看上去就有动态规划的意思,用数组记录一个元素前的某种信息,以此来达到节省搜索的时间的目的。那么放两个数组来记录就行了,一个记之前最大的,一个记之后最小的,也就是前后都要遍历一遍。一个元素可以作为pivot,那么前面不可以有比它大的,后面不可以有比它小的。要注意的是N可能为0,没有元素给出,这时需要输出的是0,无元素。题中给的是N为positive integer,怎么会为0呢?测试点2是这个东西。我不知道是我理解的问题还是出题的问题。时间复杂度算是O(n)级别,挺好。

geooorge的博客 933

甲级PAT 1101 Quick Sort (25 分)(提前打表)

1101 Quick Sort (25 分) There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the p...

Joyceyang_999的博客 321

PAT甲级刷题记录——1101 Quick Sort (25分)

There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its le...

一只奋斗中的本科生 228

PAT甲级A1101 Quick Sort (25 分)

There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its le...

vir_lee的博客 255

PAT——1101 Quick Sort 甲级

1101 Quick Sort题目题意代码解析AC代码参考 题目 https://pintia.cn/problem-sets/994805342720868352/problems/994805366343188480 题意 pivot 中心点,由题可知,快速排序的中心点就是左面都比它小、右边都比它大的位置对应的数字。题目给出一个数字序列,我们需要找出符合要求的中心点 代码解析 测试可知,一个符合要求的中心点,在排序后,其位置是不变的。但如果一个序列是降序序列,其中心位置(n为奇数时)的数的位置也是不变的

ljhsq的博客 241
上一篇: 爆刷PAT(甲级)——之【1103】 Integer Factorization (30 分)——DFS+剪枝
下一篇: 爆刷PAT(甲级)——之【1135】 Is It A Red-Black Tree (30 分)——简单模拟
仰天倀笑
博客等级 码龄10年 313粉丝 124原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值