题意:

输入一个正整数N(<=1e5),接着输入一行N个各不相同的正整数。输出可以作为快速排序枢纽点的个数并升序输出这些点的值。

trick:

测试点2格式错误原因:当答案为0时,需要换行两次。。。。。这是为何

AAAAAccepted code:

 1 #define HAVE_STRUCT_TIMESPEC
2 #include<bits/stdc++.h>
3 using namespace std;
4 int a[100007];
5 int b[100007];
6 int vis[100007];
7 int main(){
8 ios::sync_with_stdio(false);
9 cin.tie(NULL);
10 cout.tie(NULL);
11 int n;
12 cin>>n;
13 for(int i=1;i<=n;++i)
14 cin>>a[i];
15 int cnt=0;
16 int mx=0,mn=2e9;
17 for(int i=1;i<=n;++i){
18 if(a[i]>mx)
19 ++vis[i];
20 mx=max(mx,a[i]);
21 }
22 for(int i=n;i;--i){
23 if(a[i]<mn)
24 ++vis[i];
25 mn=min(mn,a[i]);
26 }
27 for(int i=1;i<=n;++i)
28 if(vis[i]==2)
29 b[++cnt]=a[i];
30 cout<<cnt<<"\n";
31 if(cnt){
32 for(int i=1;i<=cnt;++i){
33 cout<<b[i];
34 if(i<cnt)
35 cout<<" ";
36 }
37 }
38 if(cnt==0)
39 cout<<"\n";
40 return 0;
41 }

【PAT甲级】1101 Quick Sort (25 分)的更多相关文章

  1. PAT甲级——1101 Quick Sort (快速排序)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90613846 1101 Quick Sort (25 分)   ...

  2. PAT 甲级 1101 Quick Sort

    https://pintia.cn/problem-sets/994805342720868352/problems/994805366343188480 There is a classical p ...

  3. PAT甲1101 Quick Sort

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

  4. PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)

    1037 Magic Coupon (25 分)   The magic shop in Mars is offering some magic coupons. Each coupon has an ...

  5. PAT 甲级 1028 List Sorting (25 分)(排序,简单题)

    1028 List Sorting (25 分)   Excel can sort records according to any column. Now you are supposed to i ...

  6. PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

    1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following r ...

  7. 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)

    题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...

  8. 1101. Quick Sort (25)

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

  9. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

随机推荐

  1. Redis Bitmap

    Redis提供对字符串的按位操作,位图把字符串抽象成一个bool类型的数组,可以进行按位操作 比如说我有一个字符串“a” 那他的位图如下 (位) 7 6 5 4 3 2 1 0 (值) ‭0 1 0 ...

  2. Markdown进阶教程

      Markdown是很好用的轻量级标记语言,许多开发人员喜欢使用Markdown来记录学习心得和写博客.本篇博客主要介绍Markdown的高级技巧教程,Markdown的基础教程已经在上篇介绍过了. ...

  3. POJ 1330(LCA/倍增法模板)

    链接:http://poj.org/problem?id=1330 题意:q次询问求两个点u,v的LCA 思路:LCA模板题,首先找一下树的根,然后dfs预处理求LCA(u,v) AC代码: #inc ...

  4. select出来的表增加递增列

    Select identity(int,1,1) as no,* into #tmp from table

  5. TCP/IP详解,卷1:协议--链 路 层

    引言 在 T C P / I P 协议族中,链路层主要有三个目的:(1)为 I P 模块发送和 接收 I P 数据报:(2)为 A R P 模块发送 A R P 请求和接收 A R P 应答:(3)为 ...

  6. C++-POJ1020-Anniversary Cake[搜索][dfs]

    #include <set> #include <map> #include <cmath> #include <queue> #include < ...

  7. 【译】使用 Rust 和 WebAssembly 构建离线画图页面

    原文地址:https://dev.to/sendilkumarn/create-dev-s-offline-page-with-rust-and-webassembly-21gn 原文仓库:https ...

  8. koa2第一天 安装koa2

    安装全局koa2:npm install -g koa2 -generator 创建一个koa2文件夹:koa2 -e koa2 进入koa2文件夹:cd koa2 安装npm模块:npm insta ...

  9. JS实现点击table中任意元素选中

    上项目开发,忙的焦头烂额,博客也没咋更新了. 昨天老师提了个需求,简单的小例子,选择tr中任一行选中tr,觉得很有意思,记录一下: 上代码 <!DOCTYPE html> <html ...

  10. selenium的显示等待、隐式等待

    转载:https://www.cnblogs.com/mabingxue/p/10293296.html Selenium显示等待和隐式等待的区别1.selenium的显示等待原理:显示等待,就是明确 ...