快速排序有一个特点,就是在排序过程中,我们会从序列找一个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. maven的下载与安装

    下载路径:http://maven.apache.org/download.cgi 选择打红线的进行下载,我用的版本是3.3.9, 下载后解压该文件,解压后的文件内容如下: 解压完成后配置maven的 ...

  2. 安装和配置Apache服务器(下)

    Apache的配置文档:http://httpd.apache.org/docs/current/. 1.监听端口: 默认的端口号为80端口,如果端口号冲突改为8080端口. 注:每改一次httpd. ...

  3. node.js 笔记一

    现在地址:http://nodejs.org/download/ 我的机器是windows的,选择的文件是,是编译后的版本:Windows Installer (.msi)  32-bit examp ...

  4. 关于服务器端的Json文件的接收,踩了一早上的坑的问题

    JSON文件的发送和接收 服务器端接收的JSON文件也是String型的文件,因此不可以直接写成如下的格式,此错误格式下无法找到发送的{}内的数据,服务器会报错提示无法找到你需要的类型数据,也就是根本 ...

  5. SDN2017 第二次实验作业

    安装floodlight 参考链接:http://www.sdnlab.com/19189.html 从github下载源码,并编译安装 $ sudo apt-get install build-es ...

  6. 阿里八八Alpha阶段Scrum(11/12)

    今日进度 叶文滔: 合并日程界面debug成功,但是目前出现了新的问题,日程界面一些控件无法适配屏幕,正在排查问题 李嘉群: 尝试用okhttp的方式发送请求 王国超: 今天开始进行recycerli ...

  7. 设置webstorm支持ES6语法

    1.  点击File目录下的Default Settings 2.  再依次点击Languages & Frameworks  ----->  JaveScript  ----> ...

  8. canvas实例_时钟

    效果图:是一个会动的时钟 一.时钟的组成 1.表盘(蓝色)  2.刻度(黑色)  3.时针(黑色)  4.分针(黑色)  5.秒针(红色)需美化     二.主要应用的技术 Canvas画线 Canv ...

  9. Android Studio中新建和引用assets文件

    从eclipse转过的朋友们应该不太习惯AS中新建assets文件和对文件内容的引用.我也查找了网上很多资料发现很少有这样的解决答案,于是便把自己解决的方法总结在这里. 1.一般新建project后这 ...

  10. Node.js实战(十一)之Buffer

    JavaScript 语言自身只有字符串数据类型,没有二进制数据类型. 但在处理像TCP流或文件流时,必须使用到二进制数据.因此在 Node.js中,定义了一个 Buffer 类,该类用来创建一个专门 ...