【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 ...
随机推荐
- print format
python基础_格式化输出(%用法和format用法) name = 'jack' age = 18 sex = 'man' job = "IT" salary = 9999.9 ...
- python3练习100题--024
因为过生日,好几天没做题了,有点松懈. 我要更加加油啦-为了打败现在每天都厌恶的生活! 原题链接:http://www.runoob.com/python/python-exercise-exampl ...
- 关于spring boot集成MQTT
安装 说到mqtt,首先肯定要安装了,安装什么的地址:http://activemq.apache.org/ap...我本地是Windows的环境,所以装的是Windows版本,这里是第一个注意的地方 ...
- 整理收集的一些常用java工具类
1.json转换工具 package com.taotao.utils; import java.util.List; import com.fasterxml.jackson.core.JsonPr ...
- EF database first
https://www.cnblogs.com/net064/p/8024150.html 1.EF简介ADO.NET Entity Framework 是微软以 ADO.NET 为基础所发展出来的对 ...
- log设计网站,一站式一键设计log网站
log设计网站,一站式一键设计log网站 log设计网站,一键式一站式设计log网站 待办 https://www.wix.com/buildyourwebsite5/designlogo?utm_s ...
- js设计模式之实现观察者模式实例代码
前端界面 html代码 <body> <select name="" id="select"> <option value=&qu ...
- winform学习(4)控件的添加、显示和隐藏
窗体的添加.显示与隐藏 可以直接通过工具栏将某个控件直接拖动至UI界面(也可以在工具栏里双击某个控件) 也可以在代码里直接添加:窗体的标识.Controls.Add(控件标识符); Button my ...
- 水题Eating Soup
A. Eating Souptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutput ...
- 10day rpm简单用法qa ql qf "`"用法
查看软件是否安装: [root@oldboyedu ~]# rpm -qa sl -q表示查询 -a表示所有 sl-5.02-1.el7.x86_64 查看软件包中有哪些信息 [root@oldboy ...