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. 正则转nfa:bug出现。

    本人写的一个正则到nfa的bug 刚写完前面的那篇,自己用脑子过了一下,发现了一个bug.具体情况如下. 这个bug的产生条件是多次调用假名的时候,每次调用都会修改假名的nfa图.直接这么说不好理解, ...

  2. Android 使用动态加载框架DL进行插件化开发

    http://blog.csdn.net/t12x3456/article/details/39958755/ 转载自: 时之沙: http://blog.csdn.net/t12x3456

  3. HTML标签大全

    HTML标签解释大全 一.HTML标记 标签:!DOCTYPE 说明:指定了 HTML 文档遵循的文档类型定义(DTD). 标签:a 说明:标明超链接的起始或目的位置. 标签:acronym 说明:标 ...

  4. asp.net MVC 如何隐藏 Response Header 版本号

    根据借楼最少资源原则,有时候MVC需要隐藏自己的版本号,其实这里也是比较简单的,只需要在Global.ascx 的Application_Start()中添加一行代码既可 添加为  MVCHandle ...

  5. C#微信开发回复信息

    using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Web;usi ...

  6. 利用Form()使绘图可以不消失

    1: public Form1() 2: { 3: InitializeComponent(); 4: this.Show(); 5: Graphics grp = this.CreateGraphi ...

  7. AspxGridView 数据的汇总统计

    AspxGridView底部增加数据汇总行 这个功能在AspxGridView中不用复杂的代码实现, 实际上只是设置下GridView的属性而已 1. ShowFooter设置为True,即显示. 位 ...

  8. asp.net 之 GC (垃圾回收机制)

    今天抽时间好好整理了下GC相关知识,看了CSDN和博客园的几篇文章,有了一定的简单了解,决定根据个人理解整合一份随笔写下来,望诸位指教. 一:基础问题 1.首先需要知道了解什么是GC? GC如其名,就 ...

  9. Oracle学习笔记1:win7 x64下安装Oracle10g

    oracle 10g在win7x64下的安装: 第一次直接双击setup,出错了…… 可能是兼容性的问题,所以试着 右击setup-->属性-->兼容性-->勾上"以兼容模 ...

  10. 64位Windows7升级IE11后无法启动的解决办法

    1.控制面板\网络和 Internet\Internet选项 2.在高级选项卡的“安全”组配置