[P2757]导弹的召唤
来源:互联网 发布:海中金seo 编辑:程序博客网 时间:2024/04/28 15:13
原题链接
导弹拦截数据加强版
nlogn的最长上升/不上升子序列
先设一个数组low
把第一个数放进去
此时len=1
后面的数如果大于low[len]
len++
放到新的low[len]
如果小于等于low[len]
在前面找一个大于它的最小的数
顺便这里安利一下lower_bound()
用这个数来替换前面的数
二分太恶心了
不想找边界
lower_bound()是个好东西
#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<cmath>#include<queue>#include<vector>#include<climits>#include<string>#include<cstdlib>#include<map>#include<ctime>#define MAX 1000000007#define LL long longusing namespace std;int n,i,j,a[300005],h[300005],tot,ans1,ans2,low[300005],len,pos,up[300005];int part(int l,int r,int lend){ while(l<=r) { int mid=(l+r)/2; if(up[mid]>=a[lend]) { l=mid+1; } else { r=mid-1; } } return l;}int main(){ n=1; while(scanf("%d",&a[n])!=EOF) { n++; } n--;///////////////////////////////////////////////////////////// up[1]=a[1]; len=1; for(i=2;i<=n;i++) { if(a[i]<=up[len]) { len++; up[len]=a[i]; } else { pos=part(1,len,i); up[pos]=a[i]; } } ans1=len;////////////////////////////////////////////////////////////// low[1]=a[1]; len=1; for(i=2;i<=n;i++) { if(a[i]>low[len]) { len++; low[len]=a[i]; } else { pos=lower_bound(low,low+len+1,a[i])-low; low[pos]=a[i]; } } ans2=len; //////////////////////////////////////////////////////////////////// printf("%d\n%d",ans1,ans2); return 0;}
阅读全文
0 0
- [P2757]导弹的召唤
- P2757 导弹的召唤(数据加强)
- 洛谷 P2757 导弹的召唤(数据加强)
- 导弹的召唤!!!
- 洛谷-导弹的召唤(数据加强)
- 洛谷 2757 导弹的召唤 DP 解题报告
- LuoguP2757 导弹的召唤 解题报告【最长上升子序列+最长不上升子序列】
- 最后的召唤
- 海港变最后的召唤
- 召唤有丰富IOCP实践经验的同行
- 重构之恶魔的召唤!
- 快速召唤CMD的几个方法
- 中国潜艇导弹的幻想
- 追踪导弹的实现
- 导弹
- 导弹
- 导弹
- 导弹
- 电脑如何进入远程连接桌面设置界面
- Java中程序的执行过程
- 算法题,分享给需要的人
- 满足人工智能日益增长的要求
- [BZOJ3622]已经没有什么好害怕的了(容斥原理+DP)
- [P2757]导弹的召唤
- function adapter bind(C++11)
- 字符char转整形int的操作方法
- jvm垃圾收集算法
- springcloud包括哪些组件及详细说明
- JVM性能调优监控工具jps、jstack、jmap、jhat、jstat、hprof使用详解
- P2757 导弹的召唤(数据加强)
- 回溯法解决八皇后问题(java实现)
- Eclipse版本对应的jdk需求及查看Eclipse版本的方法