快速排序有一个特点,就是在排序过程中,我们会从序列找一个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. sql点滴—mysql中查询表的信息

    mysql中查询表的信息 查询mysql表字段信息的sql语句 SHOW DATABASES //列出 MySQL Server 数据库. SHOW TABLES [FROM db_name] //列 ...

  2. 判断用户访问方式为pc or Phone

    <scripttype="text/javascript"> (function () { var sUserAgent= navigator.userAgent.to ...

  3. 一道经典面试题-----setTimeout(function(){},0)

    一道经典面试题-----setTimeout(function(){},0) 转载: http://www.w3cfuns.com/notes/17398/e8a1ce8f863e8b5abb5300 ...

  4. 基础知识整理汇总 - Java学习(一)

    java 语言规范及相关文档资源 Java源码:安装目录下 src.zip 文件 java文档:https://docs.oracle.com/en/java/ 语言规范:http://docs.or ...

  5. Vmware Vcenter6.5 全新安装及群集配置介绍

    转 Vmware Vcenter6.5 全新安装及群集配置介绍 2016年12月31日 14:27:12 ccitzy01 阅读数:97772 标签: vmware   [摘要] VMwarevCen ...

  6. webstorm 2017 激活

    参考:https://blog.csdn.net/wangyingwing/article/details/79119592

  7. day1-课堂笔记

    venv   执行方法: 1,pycharm执行 2,cmd命令窗口执行:python D:\PyCharmProjects\MyProject\day1.py 回车   java原理: HW.jav ...

  8. greys java在线诊断工具

    greys是一个开源的github项目,用来分析运行中的java类.方法等信息. greys工具地址: https://github.com/oldmanpushcart/greys-anatomy/ ...

  9. Android 将系统的back键模拟成为home键的功能

    @Override public void onBackPressed() { Intent intent = new Intent(Intent.ACTION_MAIN); intent.setFl ...

  10. 微信web开发的上传图片js接口

    $('.chooseImage').click(function(){ wx.chooseImage({ count: pic_num, // 默认9,大于9也是显示9 sizeType: ['com ...