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

  大水题,正循环和倒着循环一次,统计出代码中的minnum和maxnum即可,注意最后一定要输出'\n',不然第三个测试会显示PE,格式错误。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <string>
#include <string.h>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=+;
int num[maxn];
int minnum[maxn]; //minnum[i]表示第i+1~n中最小的数
int maxnum[maxn]; //maxnum[i]表示第1~i-1中最大的数
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&num[i]);
}
num[]=;
maxnum[]=;
for(int i=;i<=n;i++){
maxnum[i]=max(maxnum[i-],num[i-]);
}
num[n+]=INF;
minnum[n+]=INF;
for(int i=n;i>=;i--){
minnum[i]=min(minnum[i+],num[i+]);
}
int res[maxn];
int cnt=;
for(int i=;i<=n;i++){
if(maxnum[i]<num[i] && num[i]<minnum[i]){
res[cnt]=num[i];
cnt++;
}
}
//sort(res,res+cnt);多次一举,因为肯定是从小到大排序的.
printf("%d\n",cnt);
if(cnt>=)
printf("%d",res[]);
for(int i=;i<cnt;i++){
printf(" %d",res[i]);
}
printf("\n");//不加这个第三个测试竟然过不去
return ;
}

PAT甲题题解-1101. Quick Sort (25)-大水题的更多相关文章

  1. 1101. Quick Sort (25)

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

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

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

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

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

  4. PAT甲题题解-1121. Damn Single (25)-水题

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789787.html特别不喜欢那些随便转载别人的原创文章又不给 ...

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

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

  6. pat1101. Quick Sort (25)

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

  7. PAT甲1101 Quick Sort

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

  8. PAT 1101 Quick Sort[一般上]

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

  9. PAT甲题题解-1117. Eddington Number(25)-(大么个大水题~)

    如题,大水题...贴个代码完事,就这么任性~~ #include <iostream> #include <cstdio> #include <algorithm> ...

随机推荐

  1. DOS 总结

    shutdown -s -t 30 指定在30秒之后自动关闭计算机. + L 返回登录页面 netstat 最近访问IP Regedit 打开注册表

  2. c++ 远程连接局域网内 数据库,并进行操作

    首先尝试利用Windows自带的dos命令窗口操作数据库:参考见https://jingyan.baidu.com/article/3aed632e19b5e8701080918f.html 1.搜索 ...

  3. 给SVN设置代理

    XP系统在C:\Documents and Settings\Administrator\Application Data\Subversion目录下 win7及以上系统在C:\Users\admin ...

  4. 页面元素固定在页面底部的纯css代码(兼容IE6)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. linux结束程序内存不会马上释放的解决方法

      Linux下频繁读写文件时,内存资源被耗尽,当程序结束后,内存不会释放需要清除缓存.Linux缓存有dentry,buffer cache,page cache. 注:Dentry用来加速文件路径 ...

  6. toFixed四舍五入精度校正

    var a = 2.255; var b = a.toFixed(2); console.log(b); 以上代码,按预期正常四舍五入得到结果应该是2.26,但实际返回值为2.25 js浮点数精度作为 ...

  7. Codeforces Round #553 (Div. 2)B. Dima and a Bad XOR 思维构造+异或警告

    题意: 给出一个矩阵n(<=500)*m(<=500)每一行任选一个数 异或在一起 求一个 异或在一起不为0 的每行的取值列号 思路: 异或的性质  交换律 x1^x2^x3==x3^x2 ...

  8. Cannot find module '../lib/utils/unsupported.js'

    运行npm run clean出错: throw err; ^ Error: Cannot find module '../lib/utils/unsupported.js' at Function. ...

  9. jmeter.bat配置(主要关于OOM)

    jmeter.bat是jmeter在windows系统下的启动文件.在使用jmeter压测,线程数设置过多时可能会报内存溢出(Out Of Memory Error),这时候可以去尝试调整一下jmet ...

  10. Java http协议概述

    一.http协议用于定义客户端与web服务端通讯的格式 二.HTTP1.0与HTTP1.1的区别 1.在HTTP1.0协议中,客户端与web服务器建立链接后只能获取一个web资源 2.HTTP1.1协 ...