A1101 Quick Sort (25 分)
一、技术总结
- 这里的一个关键就是理解调换位置排序是时,如果是元主,那么它要确保的条件就只有两个一个是,自己的位置不变,还有就是前面的元素不能有比自己大的。
二、参考代码
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int record[100000];
int main(){
int n, max = 0, count = 0;
scanf("%d", &n);
vector<int> a(n), b(n);
for(int i = 0; i < n; i++){
scanf("%d", &a[i]);
b[i] = a[i];
}
sort(a.begin(), a.end());
for(int i = 0; i < n; i++){
if(a[i] == b[i] && b[i] > max){
record[count++] = a[i];
}
if(b[i] > max) max = b[i];
}
printf("%d\n", count);
for(int i = 0; i < count; i++){
if(i != 0) printf(" ");
printf("%d", record[i]);
}
printf("\n");
return 0;
}
A1101 Quick Sort (25 分)的更多相关文章
- 【PAT甲级】1101 Quick Sort (25 分)
题意: 输入一个正整数N(<=1e5),接着输入一行N个各不相同的正整数.输出可以作为快速排序枢纽点的个数并升序输出这些点的值. trick: 测试点2格式错误原因:当答案为0时,需要换行两次
- pat1101. Quick Sort (25)
1101. Quick Sort (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng There is a ...
- PTA 09-排序3 Insertion or Heap Sort (25分)
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/676 5-14 Insertion or Heap Sort (25分) Accor ...
- 【刷题-PAT】A1101 Quick Sort (25 分)
1101 Quick Sort (25 分) There is a classical process named partition in the famous quick sort algorit ...
- 1101. Quick Sort (25)
There is a classical process named partition in the famous quick sort algorithm. In this process we ...
- A1101. Quick Sort
There is a classical process named partition in the famous quick sort algorithm. In this process we ...
- PAT甲级——A1101 Quick Sort
There is a classical process named partition in the famous quick sort algorithm. In this process we ...
- PAT (Advanced Level) 1101. Quick Sort (25)
树状数组+离散化 #include<cstdio> #include<cstring> #include<cmath> #include<map> #i ...
- PAT甲题题解-1101. Quick Sort (25)-大水题
快速排序有一个特点,就是在排序过程中,我们会从序列找一个pivot,它前面的都小于它,它后面的都大于它.题目给你n个数的序列,让你找出适合这个序列的pivot有多少个并且输出来. 大水题,正循环和倒着 ...
随机推荐
- angular6 multipart/form-data Post
一般情况下用的都是 第三种 然后碰到后台要求的是这种格式的数据 这时候我们就要修改一下我们的post 请求头,话不多说 直接上代码. 这样子的话 就ok啦!
- Python爬虫教程-实现百度翻译
使用python爬虫实现百度翻译功能python爬虫实现百度翻译: python解释器[模拟浏览器],发送[post请求],传入待[翻译的内容]作为参数,获取[百度翻译的结果] 通过开发者工具,获取发 ...
- gitlab的安装配置与简单使用
安装 gitlab,建议系统内存 6G ,不然会报错. 一.如何安装 gitlab 下载 gitlab 的 RPM 包 https://packages.gitlab.com/gitlab/gitla ...
- rxJava2.x源码解析
一. Rxjava是什么 Rxjava在GitHub的介绍是 "A library for composing asynchronous and event-based programs u ...
- Python中全局变量的引用与修改之格式影响
先来看下面的代码及执行结果: a = 1 b = [2,3] def nums(): a = 2 b[0] = 0 print(a) print(b) print(a) print(b) nums() ...
- django2-登录与出版社
1.django核心功能 因为django功能很多 ,出版社可以使用到部分功能,最快最简单了解django的运行模式,每个点后续细化去梳理 django的路由 django的视图 django的模板 ...
- call , apply的this指向实现原理并自己实现封装
实现this指向原理 var value = 'value' var obj = { value: 'obj' } function func() { console.log(this.value) ...
- 1_Swift概况
Swift 标准库 解决复杂的问题并编写高性能,可读的代码 概况 Swift标准库定义了用于编写Swift程序的基本功能,其中包括 1.如基本数据类型Int,Double以及String 2.共同的数 ...
- 记录MySql错误消息
本章列出了当你用任何主机语言调用MySQL时可能出现的错误.首先列出了服务器错误消息.其次列出了客户端程序消息. B.. 服务器错误代码和消息 服务器错误信息来自下述源文件: · 错误消息信息列在sh ...
- python基础-并发编程02
并发编程 子进程回收的两种方式 join()让主进程等待子进程结束,并回收子进程资源,主进程再结束并回收资源 from multiprocessing import Process import ti ...