hdu5256 序列变换
来源:互联网 发布:sem跟seo的比较区别 编辑:程序博客网 时间:2024/06/05 14:37
我们有一个数列A1,A2…An,你现在要求修改数量最少的元素,使得这个数列严格递增。其中无论是修改前还是修改后,每个元素都必须是整数。
请输出最少需要修改多少个元素。
题解:
这道题主要就是求一个严格递增的序列,最理想的情况是得到
1,2,3,4,5,6,7,8 ….
题目中给出的数据肯定不是这样,那么我们可以使用a[i]-i,这样会得到一个差值,这个差值代表的就是当前数和这个位置理想的数的差,令b[i]=a[i]-i的话,其实我们就是要求b[i]的非递减序列,所以代码里面我们用到的是upper_bound。
#include<iostream>using namespace std;#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<stdlib.h>#include<vector>#include<queue>#include<deque>#include<map>#include<set>#include<time.h>#define pi(x,y) printf("%d%c",(x),(y));#define pin(x) printf("%d\n",(x));#define si(x) scanf("%d",&(x))#define sii(x,y) scanf("%d%d",&(x),&(y))#define s3(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))#define rep(x,y,z) for(int (x)=(y);(x)<(z);++(x))#define dep(x,y,z) for(int (x)=(y)-1;(x)>=(z);--(x))#define read int TcaseN;scanf("%d",&TcaseN);for(int Tcase=1;Tcase<=TcaseN;++Tcase)#define cls(x,y) memset((x),(y),sizeof((x)));#define pb(x) push_back(x)#define mp(x,y) make_pair((x),(y))#define max3(value_a,value_b,value_c) max(max(value_a,value_b),value_c)#define min3(value_a,value_b,value_c) min(min(value_a,value_b),value_c)#define GT(x) (x)=clock();#define fin(x) freopen(x,"r",stdin);#define fout(x) freopen(x,"w",stdout);///In This You Can Define Long Integer Type#define LONGTYPE long longtypedef LONGTYPE LL;typedef unsigned LONGTYPE ULL;const int maxint=((~((unsigned)(0)))>>1);const LL maxll=((~((unsigned LONGTYPE)(0)))>>1);const int inf=0x3f3f3f3f;const double PI=acos(-1.0);const int N=100005;int a[N],b[N],dp[N],n;/**5051 5 3 2 481 6 3 8 9 17 12 3171 2 3 5 5 5 661 3 9 5 6 7*/int LIS(){ int len=0; for(int i=1;i<=n;++i){ int pos=upper_bound(dp,dp+n,b[i])-dp; dp[pos]=b[i]; len=max(len,pos+1); } return n-len;}int main() {#ifdef tangge clock_t tSTART,tEND,t3; GT(tSTART);#endif // tangge /*Input:*/ int T,Ti=1;scanf("%d",&T); while(T--){ dp[0]=inf; scanf("%d",&n); for(int i=1;i<=n;++i)scanf("%d",&a[i]),b[i]=a[i]-i,dp[i]=inf; printf("Case #%d:\n%d\n",Ti++,LIS()); }#ifdef tangge GT(tEND); printf("%.8lf\n",(tEND-tSTART)/1000.0);#endif // tangge return 0;}
阅读全文
0 0
- HDU5256: 序列变换
- hdu5256 序列变换
- hdu5256: 序列变换
- hdu5256【序列变换】【LIS】
- hdu5256 序列变换 dp LIS
- hdu5256 序列变换 最长递增子序列
- hdu5256 序列变换(LIS模型)
- hdu5256序列变换(非递减子序列)
- HDU5256 序列变换(LIS求严格上升子序列)
- hdu5256 序列变换 百度之星初赛第二场 最长上升子序列变形
- hdu5256序列严格递增
- hdu5256序列变幻
- 序列变换
- 序列变换
- 序列变换
- 序列变换
- NOI 2009 变换序列
- [NOI2009]变换序列
- 解决/usr/local/lib/libglog.so.0: error adding symbols: DSO missing from command line
- 树预备
- CentOS7 安装Gradle
- opencv 车牌识别
- 稳定排序之插入排序
- hdu5256 序列变换
- Tyvj P1013 找啊找啊找GF
- 十项全能革新网站开发技术-Zoomla!逐浪CMS2 x3.9.1发布
- java连接数据库
- 【代码笔记】iOS-iOS图片的原生(Graphics)
- linux服务之Apache
- Python爬虫实例——基于urlib、urlib和re实现
- 在正常系统如windows/MacOS/Linux等体验假勒索病毒WamaCry(永恒之蓝)
- 深度学习框架- 设计思维