题意:

输入一个正整数N(<=1e5),接着输入一行N个各不相同的正整数。输出可以作为快速排序枢纽点的个数并升序输出这些点的值。

trick:

测试点2格式错误原因:当答案为0时,需要换行两次。。。。。这是为何

AAAAAccepted code:

 1 #define HAVE_STRUCT_TIMESPEC
2 #include<bits/stdc++.h>
3 using namespace std;
4 int a[100007];
5 int b[100007];
6 int vis[100007];
7 int main(){
8 ios::sync_with_stdio(false);
9 cin.tie(NULL);
10 cout.tie(NULL);
11 int n;
12 cin>>n;
13 for(int i=1;i<=n;++i)
14 cin>>a[i];
15 int cnt=0;
16 int mx=0,mn=2e9;
17 for(int i=1;i<=n;++i){
18 if(a[i]>mx)
19 ++vis[i];
20 mx=max(mx,a[i]);
21 }
22 for(int i=n;i;--i){
23 if(a[i]<mn)
24 ++vis[i];
25 mn=min(mn,a[i]);
26 }
27 for(int i=1;i<=n;++i)
28 if(vis[i]==2)
29 b[++cnt]=a[i];
30 cout<<cnt<<"\n";
31 if(cnt){
32 for(int i=1;i<=cnt;++i){
33 cout<<b[i];
34 if(i<cnt)
35 cout<<" ";
36 }
37 }
38 if(cnt==0)
39 cout<<"\n";
40 return 0;
41 }

【PAT甲级】1101 Quick Sort (25 分)的更多相关文章

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

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

  2. PAT 甲级 1101 Quick Sort

    https://pintia.cn/problem-sets/994805342720868352/problems/994805366343188480 There is a classical p ...

  3. PAT甲1101 Quick Sort

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

  4. PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)

    1037 Magic Coupon (25 分)   The magic shop in Mars is offering some magic coupons. Each coupon has an ...

  5. PAT 甲级 1028 List Sorting (25 分)(排序,简单题)

    1028 List Sorting (25 分)   Excel can sort records according to any column. Now you are supposed to i ...

  6. PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

    1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following r ...

  7. 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)

    题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...

  8. 1101. Quick Sort (25)

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

  9. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

随机推荐

  1. 算法竞赛入门经典第二版 回文词P49

    #include<bits/stdc++.h> using namespace std; char rev[]="A 3 HIL JM O 2TUVWXY51SE Z 8 &qu ...

  2. Go之第三方库ini

    文章转自 快速开始 my.ini # possible values : production, development app_mode = development [paths] # Path t ...

  3. Django_静态文件/中间件/分页

    1. 静态文件配置 2. 中间件 在不修改源代码的前提下,动态的逻辑控制代码执行(装饰器) 2.1 切入函数 2.2 自定义中间件 中奖 访问限制 2.3 分页 paginator 常见错误

  4. openshift3.10集群部署

    简介 openshift是基于k8s的开源容器云. 要求 系统环境:CentOS 7.5 搭建一个master节点,两个node节点 注意: openshift3 依赖docker的版本为1.13.1 ...

  5. 自定义ViewPager,避免左右滑动时与水平滑动控件冲突

    import android.content.Context;import android.support.v4.view.ViewPager;import android.util.Attribut ...

  6. Nginx的相关介绍

    前言 说到服务器,一定会想到apache的httpd和Nginx Apache的发展时期很长,而且是毫无争议的世界第一大服务器.它有着很多优点:稳定.开源.跨平台等等.它出现的时间太长了,它兴起的年代 ...

  7. next路由跳转监听

    next的路由跳转监听事件 { “routeChangeStart”, "beforeHisroryChange" "routeChangeComplete", ...

  8. Linux /dev/sda1磁盘满了,清理办法

    转:https://blog.csdn.net/h_8410435/article/details/86303995 查看内存使用情况 df -lh Filesystem      Size  Use ...

  9. 吴裕雄 python 机器学习——主成份分析PCA降维

    # -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt from sklearn import datas ...

  10. Go性能调优

    文章引用自   Go性能调优 在计算机性能调试领域里,profiling 是指对应用程序的画像,画像就是应用程序使用 CPU 和内存的情况. Go语言是一个对性能特别看重的语言,因此语言中自带了 pr ...