思路:

最后发现对当前列车比我大的编号的栈有没有就好了,所以开个vector存一下,然后二分一下vector找一下第一个比我大的数就好了

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e5+10;
int n,a[N];
vector<int>q; int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
q.clear();
int ans=0;
for(int i=0;i<n;i++)
{
int sz=q.size();
if(!sz)
{
q.push_back(a[i]);
ans++;
}
else
{
vector<int>::iterator e=upper_bound(q.begin(),q.end(),a[i]);
if(e==q.end())
{
q.push_back(a[i]);
ans++;
}
else
{
int d=e-q.begin();
q[d]=a[i];
}
}
} printf("%d\n",ans);
return 0;
}

PAT L2-014【二分】的更多相关文章

  1. pat甲级1044二分查找

    1044 Shopping in Mars(25 分) Shopping in Mars is quite a different experience. The Mars people pay by ...

  2. PAT 1010 Radix (二分)

    Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...

  3. xdoj 2020校赛复盘

    平时写东西都不喜欢复盘,这肯定不是一个好习惯,感觉每次花好几个小时甚至好几天写题目然后没写出来也不去看题解是一种很蠢的行为( 花了这么久时间打校赛,虽然水平很low,数据结构也不太会用,还是记录一下自 ...

  4. loj#6072 苹果树(折半搜索,矩阵树定理,容斥)

    loj#6072 苹果树(折半搜索,矩阵树定理,容斥) loj 题解时间 $ n \le 40 $ . 无比精确的数字. 很明显只要一个方案不超过 $ limits $ ,之后的计算就跟选哪个没关系了 ...

  5. PAT 1044 Shopping in Mars[二分][难]

    1044 Shopping in Mars(25 分) Shopping in Mars is quite a different experience. The Mars people pay by ...

  6. PAT甲级1057 Stack【树状数组】【二分】

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805417945710592 题意:对一个栈进行push, pop和 ...

  7. PAT甲1077 Kuchiguse【字符串】【暴力】【Hash】【二分】

    1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...

  8. PAT 甲级 1010 Radix (25)(25 分)进制匹配(听说要用二分,历经坎坷,终于AC)

    1010 Radix (25)(25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 ...

  9. PAT甲级1010踩坑记录(二分查找)——10测试点未过待更新

    题目分析: 首先这题有很多的坑点,我在写完之后依旧还有第10个测试点没有通过,而且代码写的不优美比较冗长勿喷,本篇博客用于记录写这道题的一些注意点 1.关于两个不同进制的数比大小一般采用将两个数都转化 ...

随机推荐

  1. 一张图理解is_nll isset empty

    isset 判断变量是否已存在,如果变量存在则返回 TRUE,否则返回 FALSE. empty 判断变量是否为空,如果变量是非空 或非零 的值,则 empty() 返回 FALSE.换句话说,&qu ...

  2. Spring MVC的工作原理和机制

    Spring  MVC的工作原理和机制 参考: springMVC 的工作原理和机制 - 孤鸿子 - 博客园https://www.cnblogs.com/zbf1214/p/5265117.html ...

  3. invalid constant type: 18

    javassist 3.18以下的版本不支持在JDK1.8下运行

  4. Jmete基础使用

    1,jmeter下载与安装 Jmeter的运行需要JDK支持,所以需要先安装好jdk,并配置好环境变量: 下载地址:http://jmeter.apache.org/download_jmeter.c ...

  5. Java企业微信开发_00_源码及资源汇总贴

    一.源码 此系列教程的源码我都放在了github上,欢迎fork以及关注. 传送门:https://github.com/shirayner/WeiXin_QiYe_Demo/tree/master ...

  6. STL stl_alloc.h

    # // Comment By: 凝霜 # // E-mail: mdl2009@vip.qq.com # // Blog: http://blog.csdn.net/mdl13412 # # // ...

  7. informix 把数据从一个表倒到另外一个表中

    drop table zrjReinUnClaimTmpT; create table zrjReinUnClaimTmpT ( mainid SERIAL not null, RepayNo var ...

  8. tarjan求割点

    首先给大家一个网址讲的比较细:http://www.cnblogs.com/en-heng/p/4002658.html 如果还有不懂的话,可以回来再看看我的文章; 概念明确: 树边:(在[2]中称为 ...

  9. 浅谈vue路由原理

    Vue的路由实现:hash模式 和 history模式 hash模式:在浏览器中符号“#”,#以及#后面的字符称之为hash,用window.location.hash读取: 特点:hash虽然在UR ...

  10. Android的缓存图片不在系统图库中显示的解决办法

    Android的图库会在开机的时候扫描SD卡中的图片,视频等文件,有很多App的私有图片不想在图库中显示,就需要另外处理了. 解决办法:在缓存图片的文件夹中创建 .nomedia 文件. 1. &qu ...