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有多少个并且输出来. 大水题,正循环和倒着 ...
随机推荐
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A. Math Problem 水题
A. Math Problem Your math teacher gave you the following problem: There are n segments on the x-axis ...
- xml模块(了解)
目录 一.xml简介 二.Python使用xml 三.自己创建xml文档 一.xml简介 xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单,不过,古时候,在 ...
- Fuzzy finder(fzf+vim) 使用入门指南
今天无意中尝试了fzf,才发现这个工具的威力无穷,毕竟是非常好的工具,第一次都把它的优点都释放出来也不现实,先熟悉一下吧,后面在实战中再不断地学习总结. 它是什么: Fuzzy finder 是一款使 ...
- Linux 部署 rabbitMQ集群
1. 部署Erlang 1.1 RabbitMQ依赖于Erlang,版本对应请查看 https://www.rabbitmq.com/which-erlang.html 1.2 下载安装Erlang ...
- 简单node服务器demo,麻雀虽小,五脏俱全
//本服务器要实现的功能如下: //1.静态资源服务器(能读取静态资源) //2.能接收get请求,并能处理参数 //3.能接收post请求,并能处理参数 const http = require(' ...
- mysql 数据库分表小实例
项目开发中,我们的数据库数据越来越大,随之而来的是单个表中数据太多.以至于查询书读变慢,而且由于表的锁机制导致应用操作也搜到严重影响,出现了数据库性能瓶颈. 当出现这种情况时,我们可以考虑分表,即将单 ...
- Web前端——css
css 推荐的样式编写顺序: Positioning:定位 Box model:盒子模型.大小等 Typographic:文字系列.排印等 Visual:可视化.背景等 Misc:其它混杂模式 居中 ...
- SpringBoot(14)—注解装配Bean
SpringBoot(14)-注解装配Bean SpringBoot装配Bean方式主要有两种 通过Java配置文件@Bean的方式定义Bean. 通过注解扫描的方式@Component/@Compo ...
- 运行时报:尝试加载 Oracle 客户端库时引发 BadImageFormatException,如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题
运行环境为: Windows Server2012 Oracle11g 32位数据库+客户端 IIS发布后提示错误信息: “尝试加载 Oracle 客户端库时引发 BadImageFormatExc ...
- vscode 设置代码格式化缩进为2个空格
打开文件——>首选——>设置 输入搜索 tabsize 按照下图设置即可,然后打开 注意:如果不将Detect Indentation 勾选取消 以前用tab创建的忘记依然为4个空格