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 pivot to its right. Given N distinct positive integers after a run of partition, could you tell how many elements could be the selected pivot for this partition?

For example, given N = 5 and the numbers 1, 3, 2, 4, and 5. We have:

  • 1 could be the pivot since there is no element to its left and all the elements to its right are larger than it;
  • 3 must not be the pivot since although all the elements to its left are smaller, the number 2 to its right is less than it as well;
  • 2 must not be the pivot since although all the elements to its right are larger, the number 3 to its left is larger than it as well;
  • and for the similar reason, 4 and 5 could also be the pivot.

    Hence in total there are 3 pivot candidates.

    Input Specification:

    Each input file contains one test case. For each case, the first line gives a positive integer N (<= 105). Then the next line contains N distinct positive integers no larger than 109. The numbers in a line are separated by spaces.

    Output Specification:

    For each test case, output in the first line the number of pivot candidates. Then in the next line print these candidates in increasing order. There must be exactly 1 space between two adjacent numbers, and no extra space at the end of each line.

    Sample Input:

    5
    1 3 2 4 5

    Sample Output:

    3
    1 4 5
  •  #include<stdio.h>
    #include<string>
    #include<iostream>
    #include<string.h>
    #include<sstream>
    #include<vector>
    #include<map>
    using namespace std;
    bool is[];
    int main()
    {
    int n;
    int MAX = -,MIN = ,tem;
    vector<int> vv,re;
    scanf("%d",&n);
    for(int i = ;i <n;++i)
    {
    scanf("%d",&tem);
    if(tem > MAX)
    {
    is[i] = ;
    MAX = tem;
    }
    vv.push_back(tem);
    }
    for(int i = n-;i >=;--i)
    {
    if(vv[i] < MIN)
    {
    MIN = vv[i];
    if(is[i]) re.push_back(vv[i]);
    }
    else is[i] = ;
    }
    printf("%d\n",re.size());
    for(int i = re.size() - ;i >= ;--i)
    {
    if(i == re.size() - ) printf("%d",re[i]);
    else printf(" %d",re[i]);
    }
    printf("\n");
    return ;
    }

1101. Quick Sort (25)的更多相关文章

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

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

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

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

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

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

  4. pat1101. Quick Sort (25)

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

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

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

  6. PAT甲1101 Quick Sort

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

  7. PAT 1101 Quick Sort[一般上]

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

  8. 1101 Quick Sort(25 分

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

  9. 1101 Quick Sort

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

随机推荐

  1. Oracle 基础 <1> --存储过程

    一.子程序 子程序是已命名的PL/SQL块,它们存储在数据库中,可以Wie它们指定参数,可以从任何数据库客户端和应用程序中调用它们.子程序包括存储过程和函数. 子程序包括: 1.声明部分:声明部分包括 ...

  2. 怒刷DP之 HDU 1029

    Ignatius and the Princess IV Time Limit:1000MS     Memory Limit:32767KB     64bit IO Format:%I64d &a ...

  3. 剑指Offer38 数组所有数字出现两次,只有两个出现了一次,找出这两个数字

    /************************************************************************* > File Name: 38_Number ...

  4. poj 1947 树形dp

    思路:dp[i][j]表示,以i节点为根,删去j个节点最少要断几条边. 那么dp[u][j]=min(dp[u][j],dp[v][k]+dp[u][j-k]);//选取最优状态 dp[u][j]=m ...

  5. ASP三种常用传值方式:

    ASP 页面(两个aspx页面)传值方式:背景: 两个aspx 页面valuepage.aspx tbusername tbpwdobtainvalue.aspx tbusername tbpwd 1 ...

  6. jquery 触发a链接点击事件

    jquery 触发a链接点击事件 <p class="btnSubmit"><a href="javascript:submitData();" ...

  7. C#实现在CAD图纸中插入另一个DWG图块的代码

    C#实现在CAD图纸中插入另一个DWG图块的代码 PromptPointResult ppr = ed.GetPoint("请选择插入点:"); Point3d pt = ppr. ...

  8. 如何使用10个小时搭建出个人域名而又Geek的独立博客?

    1.安装准备软件 Node.js.Git.GitHub DeskTop(前两个必须安装,后者可选) 2.本地搭建hexo框架.配置主题.修改参数.实现本地测试预览 3.链接GitHub.实现在线预览 ...

  9. 第十一篇、微信小程序-input组件

    主要属性: 效果图: ml: <!--style的优先级比class高会覆盖和class相同属性--> <!--头像--> <view style="displ ...

  10. 20141104--SQL连接查询,联合查询

    ---------------------------连接查询-------------------------------- --横向连接查询 --可以将子查询放在from之前,用来替换显示出来的信 ...