1101. Quick Sort (25)快排
来源:互联网 发布:win10网络时间同步 编辑:程序博客网 时间:2024/06/16 14:42
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:
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:51 3 2 4 5Sample Output:
31 4 5
此题有坑,当结果为0时,也要跟着打印一行空行。
#include<iostream>#include<algorithm>#include<cstdio>using namespace std;int num[100005];int num2[100005];int num3[100005],le=-1;int main(){ int n; int index1=0; scanf("%d",&n); for (int i=0;i<n;i++) { scanf("%d",&num[i]); num3[i]=num[i]; } sort(num3,num3+n); for (int i=0;i<n;i++) { if (le<num[i]) le=num[i]; if (num[i]==num3[i]&&num[i]==le) num2[index1++]=num[i]; } printf("%d\n",index1); for (int i=0;i<index1;i++) { printf("%d",num2[i]); if (i!=index1-1) printf(" "); } printf("\n"); return 0;}
- 1101. Quick Sort (25)[快排]
- 1101. Quick Sort (25)快排
- 快排(Quick Sort)
- 1101. Quick Sort (25)【快排】——PAT (Advanced Level) Practise
- 快排Quick Sort到底有多快?
- 快排qsort/sort
- HDU1425 <sort 快排>
- STL sort快排
- sort快排
- 1101. Quick Sort (25)
- 1101. Quick Sort (25)
- 1101. Quick Sort (25)
- 1101. Quick Sort (25)
- 1101. Quick Sort (25)
- 1101. Quick Sort (25)
- 1101. Quick Sort (25)
- 1101. Quick Sort (25)
- 1101. Quick Sort (25)
- Codeforces 651E Table Compression 拓扑序
- Java设计模式--工厂方法模式
- 数组中Arrays工具类方法的应用
- 计蒜客 踩蚂蚁(优先队列)
- 7、集合
- 1101. Quick Sort (25)快排
- A
- 机器学习第三周(三)--正则化
- 大数据 (九)Hadoop-使用eclipe插件操作HDFS
- UVA12338Anti-Rhyme Pairs(哈希+二分最长前缀)
- hdu6063RXD and math(快速幂找规律)
- python random和numpy random
- 微信支付接口升级,微信支付免充值代金券开通
- C++学习之容器<vector>