【PAT甲级】1101 Quick Sort (25 分)
题意:
输入一个正整数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 分)的更多相关文章
- PAT甲级——1101 Quick Sort (快速排序)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90613846 1101 Quick Sort (25 分) ...
- PAT 甲级 1101 Quick Sort
https://pintia.cn/problem-sets/994805342720868352/problems/994805366343188480 There is a classical p ...
- PAT甲1101 Quick Sort
1101 Quick Sort (25 分) There is a classical process named partition in the famous quick sort algorit ...
- PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)
1037 Magic Coupon (25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an ...
- PAT 甲级 1028 List Sorting (25 分)(排序,简单题)
1028 List Sorting (25 分) Excel can sort records according to any column. Now you are supposed to i ...
- PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following r ...
- 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)
题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...
- 1101. Quick Sort (25)
There is a classical process named partition in the famous quick sort algorithm. In this process we ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
随机推荐
- [CF1236D] Alice and the Doll - 模拟,STL
[CF1236D] Alice and the Doll Description \(N \times M\)网格,有 \(K\) 个格子里有障碍物.每次经过一个格子的时候只能直走或者右转一次.初态在 ...
- Linux MYSQL安装指南
安装环境:系统是 centos6.5 1.下载 下载地址:http://dev.mysql.com/downloads/mysql/5.6.html#downloads 下载版本:我这里选择的5.6. ...
- Android基础知识 -- Fragment
Fragment是android3.0后提供的API(所以android:minSdkVersion="11"以上版本),主要针对平板UI.有自己的生命周期,但是必须依附在Acti ...
- js面向对象的程序设计 --- 上篇(理解对象)
前言 ECMAScript中没有类的概念,因此它们的对象与基于类的语言中的对象有所不同. ECMA-262把对象定义为:"无序的集合属性,其属性可以包含基本值,对象或者函数".正因 ...
- ASP.NET + MVC5 入门完整教程三 (下) ---MVC 松耦合
建立松耦合组件 MVC 模式最重要的特性之一视他支持关注分离,希望应用程序中的组件尽可能独立,只有很少的几个可控依赖项.在理想的情况下,每个组件都不了解其他组件,而只是通过抽象接口来处理应用程序的其他 ...
- AcWing 前缀和 一维加二维
一维 #include<bits/stdc++.h> using namespace std; ; int n,m; int a[N],s[N]; int main(){ ios::syn ...
- 一些 NuGet 程序包是使用不同于当前目标框架的目标框架安装的,可能需要重新安装
如果 NuGet 检测到包受到重定向或升级项目的影响,它会将 packages.config 中的 requireReinstallation="true" 属性添加到所有受影响的 ...
- MySql 怎么存取 Emoji
01.前言 Emoji 在我们生活中真的是越来越常见了,几乎每次发消息的时候不带个 Emoji,总觉得少了点什么,似乎干巴巴的文字已经无法承载我们丰富的感情了.对于我们开发者来说,如何将 Emoji ...
- es6模块化设计
//导出 //方式一 export const name = 'hello' export let addr = 'chengdu' export var list = [1,2,3] //方式二 c ...
- 《Qt Quick核心编程》勘误
本文将结合章节和问题发现的先后顺序来编排,具体是酱紫的:每个章节单列出来作为本文的一节,在该节下按时间顺序列出发现的问题. 第4章 1). 51页第六行:“ iconName 属性定图标的名字”,其中 ...