一、技术总结

  1. 这里的一个关键就是理解调换位置排序是时,如果是元主,那么它要确保的条件就只有两个一个是,自己的位置不变,还有就是前面的元素不能有比自己大的。

二、参考代码

#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 分)的更多相关文章

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

    题意: 输入一个正整数N(<=1e5),接着输入一行N个各不相同的正整数.输出可以作为快速排序枢纽点的个数并升序输出这些点的值. trick: 测试点2格式错误原因:当答案为0时,需要换行两次

  2. pat1101. Quick Sort (25)

    1101. Quick Sort (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng There is a ...

  3. 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 ...

  4. 【刷题-PAT】A1101 Quick Sort (25 分)

    1101 Quick Sort (25 分) There is a classical process named partition in the famous quick sort algorit ...

  5. 1101. Quick Sort (25)

    There is a classical process named partition in the famous quick sort algorithm. In this process we ...

  6. A1101. Quick Sort

    There is a classical process named partition in the famous quick sort algorithm. In this process we ...

  7. PAT甲级——A1101 Quick Sort

    There is a classical process named partition in the famous quick sort algorithm. In this process we ...

  8. PAT (Advanced Level) 1101. Quick Sort (25)

    树状数组+离散化 #include<cstdio> #include<cstring> #include<cmath> #include<map> #i ...

  9. PAT甲题题解-1101. Quick Sort (25)-大水题

    快速排序有一个特点,就是在排序过程中,我们会从序列找一个pivot,它前面的都小于它,它后面的都大于它.题目给你n个数的序列,让你找出适合这个序列的pivot有多少个并且输出来. 大水题,正循环和倒着 ...

随机推荐

  1. 这样修改有哪些优缺点 wcf service via attribute setting vs config

    客户要恢复数据,结果就是block在某个阶段,在server端log一圈下来,发现原来是client端出了问题,就是这个log: ERROR - Identity check failed for o ...

  2. 【51nod1253】Kundu and Tree(容斥+并查集)

    点此看题面 大致题意: 给你一棵树,每条边为黑色或红色, 求有多少个三元组\((x,y,z)\),使得路径\((x,y),(x,z),(y,z)\)上都存在至少一条红色边. 容斥 我们可以借助容斥思想 ...

  3. import和from...import

    目录 一.import 模块名 二.from 模块名 import 具体的功能 三.import和from...import...的异同 一般使用import和from...import...导入模块 ...

  4. React Hooks用法大全

    前言 在 React 的世界中,有容器组件和 UI 组件之分,在 React Hooks 出现之前,UI 组件我们可以使用函数,无状态组件来展示 UI,而对于容器组件,函数组件就显得无能为力,我们依赖 ...

  5. vue中\$refs、\$emit、$on的使用场景

    1.$emit的使用场景 子组件调用父组件的方法并传递数据注意:子组件标签中的时间也不区分大小写要用“-”隔开 子组件: <template> <button @click=&quo ...

  6. Spring 中AOP及前后置增强案例

    1.AOP面向切面编程 面向切面编程的本质:面向切面编程,指扩展功能不修改源代码,将功能代码从业务逻辑代码中分离出来.  1主要功能:日志记录,性能统计,安全控制,事务处理,异常处理等等.  2主要意 ...

  7. visdom 简单使用

     官方网址: https://github.com/facebookresearch/visdom 入门教程: http://www.ainoobtech.com/pytorch/pytorch-v ...

  8. ansible命令参数介绍

    -m:要执行的模块,默认为command -a:模块的参数 -u:ssh连接的用户名,默认用root,ansible.cfg中可以配置 -k:提示输入ssh登录密码.当使用密码验证的时候用 -s:su ...

  9. 使用celery执行Django串行异步任务

    Django项目有一个耗时较长的update过程,希望在接到请求运行update过程的时候,Django应用仍能正常处理其他的请求,并且update过程要求不能并行,也不能漏掉任何一个请求 使用cel ...

  10. C# ICloneable,shallow clone,deep clone.

    [Serializable] public class Person:ICloneable { public string Name { get; set; } public int Id { get ...