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> ...
随机推荐
- sql点滴43—mysql允许用户远程登陆
方法1 局域网连接mysql报错: ERROR 1130: Host '192.168.0.220' is not allowed to connect to this MySQL server 解 ...
- 将jar包添加到maven仓库
Maven资源库配置 访问http://mvnrepository.com/,在搜索栏中输入你要搜索的 JAR 包的关键字 例如下载ImpalaJDBC41这个jar包 选择你想要下载的Jar包版 ...
- CSS的六种定位模型
定位模型 2017年6月8日 fanbright css支持6种定位模型 静态 绝对 固定 相对 浮动 相对浮动 设定位置 position:static;可以取消元素的定位设置,使之恢复为原先在常规 ...
- BZOJ3155:Preprefix sum(线段树)
Description Input 第一行给出两个整数N,M.分别表示序列长度和操作个数 接下来一行有N个数,即给定的序列a1,a2,....an 接下来M行,每行对应一个操作,格式见题目描述 Out ...
- OpenCV——距离变换与分水岭算法的(图像分割)
C++: void distanceTransform(InputArray src, OutputArray dst, int distanceType, int maskSize) 参数详解: I ...
- PAT B1005 继续(3n+1)猜想 (25 分)
卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对 n=3 进行验证的时 ...
- calico 排错记录 apt-get install telnet
1.用kubespray部署一个单节点集群,kubectl get pods -n kube-system,结果: calico-node-7v8wx 1/1 Running 0 2dcalico-n ...
- opencv7-ml之统计模型
在opencv的ml模块中有个统计模型类,而其他的比如朴素贝叶斯分类器.knn.svm等等其他模型都是基于该模型上派生出来的.所以先介绍下该模型. 该类的定义在文件"opencv\sourc ...
- DC-DC Controllers Use Average-Current-Mode Control for Infotainment Applications-3939
DC-DC Controllers Use Average-Current-Mode Control for Infotainment Applications Abstract: Auto info ...
- 20155317王新玮《网络对抗技术》实验8 WEB基础实践
20155317王新玮<网络对抗技术>实验8 WEB基础实践 一.实验准备 1.0 实验目标和内容 Web前端HTML.能正常安装.启停Apache.理解HTML,理解表单,理解GET与P ...