hdu 序列变换
来源:互联网 发布:星星知我心演员 编辑:程序博客网 时间:2024/06/07 07:11
序列变换我们需要的是一个修改以后的最长递增子序列
因为修改的数只能是整数
所以我们的还要考虑数是否可以修改
我们对所有输入的数减去i也就是他们的位置
这样我们就只需要求最长非递减子序列即可
n的时间复杂度太罗嗦了
我们log(n)的还好说。。、
正常的最长递增子序列是利用stl 函数的lower_bound
这里我们要的是非递减子序列
用upper_bound即可
stl的upper的应用
#include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;int a[100003];int b[100003];int solve(int n){ int s=0; b[++s]=a[0]; for(int i=1;i<n;i++) { if(a[i]>=b[s]) b[++s]=a[i]; else { int z=upper_bound(b+1,b+s,a[i])-b; b[z]=a[i]; } } return s;}int main(){ int T; scanf("%d",&T); int time=0; while(T--) { int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i]); a[i]-=i; } int ans=n-solve(n); printf("Case #%d:\n",++time); printf("%d\n",ans); }}如果还想看类似的题可以点开
here
B - 序列变换
0 0
- Hdu 5256 序列变换
- hdu 5256 序列变换
- HDU 5256 序列变换
- HDU 5248 序列变换
- HDU 5256 序列变换
- HDU 5256 序列变换
- HDU 5256 序列变换
- hdu 序列变换
- hdu 5248 序列变换【二分】
- HDU ACM 5256 序列变换
- HDU-5256 序列变换(LIS)
- HDU 5248 序列变换 —— 二分
- 【HDU】5248-序列变换(贪心+二分)
- hdu 5256 序列变换 (LIS变形)
- HDU - 5256 序列变换 (LIS转化)
- HDU - 5248 序列变换 (二分&技巧)
- 【HDU】5256 - 序列变换(LIS)
- HDU 5256 (序列变换 LIS)
- k-means聚类算法
- 2017跟着小虎玩着去软考--趣味好玩解析2015年下半年信息系统项目管理师上午试题66-70题
- java学习笔记(十一)封装、this关键字与static
- error MSB6006: "cmd.exe" exited with code 3. / Cannot open include file: 'QtCore/qglobal.h': No such
- Ubuntu+Spark+IDEA+SBT+scala项目搭建流程记录
- hdu 序列变换
- POJ 1837
- vs2017无法登陆
- 鳥哥的 Linux 私房菜
- Dll注入经典方法完整版
- windows服务器修改远程登录的端口+防火墙配置
- 智能指针
- mybatis 报错
- UGUI背包实现详解之三——UGUI中如何代码实现背包精灵物品互换拖拽效果