PAT甲题题解-1101. Quick Sort (25)-大水题
快速排序有一个特点,就是在排序过程中,我们会从序列找一个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)-大水题的更多相关文章
- 1101. Quick Sort (25)
There is a classical process named partition in the famous quick sort algorithm. In this process we ...
- PAT (Advanced Level) 1101. Quick Sort (25)
树状数组+离散化 #include<cstdio> #include<cstring> #include<cmath> #include<map> #i ...
- 【PAT甲级】1101 Quick Sort (25 分)
题意: 输入一个正整数N(<=1e5),接着输入一行N个各不相同的正整数.输出可以作为快速排序枢纽点的个数并升序输出这些点的值. trick: 测试点2格式错误原因:当答案为0时,需要换行两次
- PAT甲题题解-1121. Damn Single (25)-水题
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789787.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲级——1101 Quick Sort (快速排序)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90613846 1101 Quick Sort (25 分) ...
- pat1101. Quick Sort (25)
1101. Quick Sort (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng There is a ...
- PAT甲1101 Quick Sort
1101 Quick Sort (25 分) There is a classical process named partition in the famous quick sort algorit ...
- PAT 1101 Quick Sort[一般上]
1101 Quick Sort(25 分) There is a classical process named partition in the famous quick sort algorith ...
- PAT甲题题解-1117. Eddington Number(25)-(大么个大水题~)
如题,大水题...贴个代码完事,就这么任性~~ #include <iostream> #include <cstdio> #include <algorithm> ...
随机推荐
- 数值分析 最小二乘 matlab
1. 已知函数在下列各点的值为 -1 -0.75 -0.5 0 0.25 0.5 0.75 1.00 0.8125 0.75 1.00 1.3125 1.75 2.3125 分别用一次.二次. ...
- 第 15 章 位操作(binbit)
/*------------------------------------ binbit.c -- 使用位操作显示二进制 ------------------------------------*/ ...
- Beta阶段第三次冲刺
Beta阶段第三次冲刺 严格按照Git标准来,组员有上传Git的才有贡献分没有的为0 代码签入图 1.part1 -站立式会议照片 2.part2 -项目燃尽图 3.part3 -项目进展 1.正在进 ...
- 极限编程核心价值:尊重(Respect)
原文:https://deviq.com/respect 极限编程核心价值:简单(Simplicity) 极限编程核心价值:沟通(Communication) 极限编程核心价值:反馈(Feedback ...
- [python]python官方原版编码规范路径
1.进入python官方主页:https://www.python.org/ 2.按如下图进入PEP Index 3.选择第8个,即为python的规范
- 原生js返回顶部(匀速、由快到慢)
在项目中我们经常有需求要求页面滚动到一定位置时出现返回顶部按钮,点击即返回顶部. 方法一: 锚点,这是最简单的.(a标签的href属性等于一直要到达位置元素的id值) 方法二: js直接给页面根节点设 ...
- linux,添加新硬盘的方法
一.物理机添加一块新的硬盘方法(目的是把后加的磁盘直接加在现有的上面,不用再分区挂载)1.首先要确定现有系统在那块盘上 [root@localhost ~]# df -lhFilesystem ...
- InnerClass annotations are missing corresponding EnclosingMember annotations. Such InnerClas...
如果 你的项目中使用了注解插件 比如butterknife 升级3.1之后打包编译 出现以下错误提示 InnerClass annotations are missing correspondi ...
- vue之常用指令
事件缩写 v-on:click= 简写方式 @click= 事件对象$event <!DOCTYPE html> <html lang="en"> < ...
- leetcode63—Unique Path II
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...