【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 ...
随机推荐
- ORA-01843: not a valid month
问题描述 ORA-01843: not a valid month oracle数据库插入出现无效的月份
- 时间日期转换工具类,获取当前时间YYYYMMDD24HHMISS、YYYYMMDDHHMISS
YYYYMMDD24HHMISS:24小时制时间(显示上只是比YYYYMMDDHHMISS中间多了一个24),例:2018102224112440 YYYYMMDDHHMISS:12小时制时间,例20 ...
- js正则表达式验证端口范围(0-65535)
javascript正则表达式验证IP地址的端口合法性 if (!(/^[1-9]\d*$/.test(port) && 1 <= 1 * port && 1 * ...
- <context:component-scan>标签
在spring-mvc的配置文件Springmvc-servlet.xml中,要扫描Controller注解的类,用<context:include-filter>标签 <conte ...
- Ninject 2.x细说---2.绑定和作用域
Ninject 2.x细说---2.绑定和作用域 转载weixin_33725272 最后发布于2011-11-06 00:03:00 阅读数 9 收藏 Ninject中提供多种接口和实现类的绑 ...
- 网络https工作原理
网络https工作原理 待办 https://www.runoob.com/w3cnote/https-ssl-intro.html
- php对字符串的操作4之 字符串的格式化函数
strtolower($str ) strtoupper($str ) 大小写转换 strtotime('2018-1-1 0:0') 字符串转时间戳 date('Y-m-d H:i:s',time( ...
- .NTE Core Web API Example
Source from :https://www.codeproject.com/Articles/1260600/Speed-up-ASP-NET-Core-WEB-API-application- ...
- Vue学习 Day01
介绍 这个系列记录自己学习Vue的过程. Vue官方不推荐新手直接使用 vue-cli,所以前面这几天都是根据官方文档学习. 步骤 新建一个html文件. 在html中导入vue.js依赖. < ...
- docker里面安装sqlserver2017
首先要注意,docker一般不做数据持久化容器.如果非要安装可以参考微软官方教程: https://docs.microsoft.com/zh-cn/sql/linux/quickstart-inst ...