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 (≤). Then the next line contains N distinct positive integers no larger than 1. 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 <iostream>
#include <vector>
#include <queue>
using namespace std;
int N, nums[], minN[], maxN[], res = , resNum[];//左边最大值(包括自己),右边最小值
int main()
{
cin >> N;
for (int i = ; i < N; ++i)
cin >> nums[i];
for (int i = ; i < N; ++i)//找到每个位置左边最大的值,不包括自己
maxN[i] = max(maxN[i - ], nums[i - ]);
minN[N - ] = ;
for (int i = N-; i >= ; --i)//找到每个位置右边最小的值,不包括自己
minN[i] = min(minN[i + ], nums[i + ]);
for (int i = ; i < N; ++i)
if (nums[i] > maxN[i] && nums[i] < minN[i])
resNum[res++] = nums[i];
cout << res << endl;
for (int i = ; i < res; ++i)
cout << resNum[i] << (i == res - ? "" : " ");
cout << endl;
return ;
}

最新文章

  1. CobarClient源码分析(1)
  2. jquery中的get和set
  3. boost:进程管理
  4. NGUI的UIProgressBar使用裁剪方式而不是压缩方式的方法
  5. HDU 1754 I Hate It 线段树 单点更新 区间最大值
  6. (三)映射对象标识符(OID)
  7. poj2187(未完、有错)
  8. myBatIs.Net 调用Oracle 存储过程返回游标
  9. html5学习(二)音频audio
  10. Setting DPDK+OVS+QEMU on CentOS
  11. Python大神成长之路: 第一次学习记录
  12. python day2 练习题
  13. .net通用防SQL注入漏洞程序(Global.asax方式)
  14. NancyFX 第八章 内容协商
  15. HTML入门笔记案例展示(1)
  16. 多线程——C++
  17. 简单聊聊WebSocket
  18. Linux内核分析第四章读书笔记
  19. (递推)一只小蜜蜂... hdu2044
  20. Struts通配符映射

热门文章

  1. jdbc出现中文乱码的解决办法
  2. Django 前后端数据传输、ajax、分页器
  3. elasticsearch内存耗尽的问题
  4. 校园商铺-2项目设计和框架搭建-9验证Service
  5. windows 嵌入控制台
  6. R语言 循环
  7. Parse-轻松构建移动APP的后台服务
  8. 2015年MBA备考心得
  9. 二分查找总结及部分Lintcode题目分析 4
  10. SpringCloud学习笔记(六):Feign+Ribbon负载均衡