hdu5773The All-purpose Zero,1257最少拦截次数
来源:互联网 发布:yum安装本地rpm包命令 编辑:程序博客网 时间:2024/06/15 17:35
这次的两题都是求连续的递增序列,我主要是用求最长连续子序列的方法解决的,核心(int po=lower_bound(ans,ans+len,b[i])-ans;),理解这句代码,节能解决一类题
5773The All-purpose Zero
#include<cstring>#include<cstdio>#include<algorithm>using namespace std;int a[100001],ans[100001],b[100001];int main(){ int i,t,n,zero,count,len,h=1,flag; scanf("%d",&t); while(t--) { zero=0; count=0; flag=1; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i]); } memset(b,0,sizeof(b)); memset(ans,0,sizeof(ans)); for(i=1;i<=n;i++) { if(a[i]==0) zero++; else { flag=0; b[count++]=a[i]-zero; } } ans[0]=b[0]; len=1; for(i=1;i<count;i++) { if(ans[len-1]<b[i]) ans[len++]=b[i]; else { int po=lower_bound(ans,ans+len,b[i])-ans; ans[po]=b[i]; } } if(flag==1) len=0; printf("Case #%d: %d\n",h++,len+zero); } return 0;}
1257最少拦截次数
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[100001],b[100001];int main(){ int n,i,count; while(scanf("%d",&n)!=EOF) { count=0; for(i=1;i<=n;i++) { scanf("%d",&a[i]); } b[0]=a[0]; int len=1; for(i=1;i<=n;i++) { if(b[len-1]<a[i]) b[len++]=a[i]; else { int pos = lower_bound(b,b+len,a[i])-b; b[pos] = a[i]; } } printf("%d\n",len-1); } }
1 0
- hdu5773The All-purpose Zero,1257最少拦截次数
- hdu5773The All-purpose Zero
- The All-purpose Zero
- The All-purpose Zero
- The All-purpose Zero
- The All-purpose Zero
- hdu5773 The All-purpose Zero
- HDU5773 The All-purpose Zero
- hduThe All-purpose Zero+LIS
- hdoj5773The All-purpose Zero【LIS】
- HDU5773:The All-purpose Zero
- The All-purpose Zero-HDU5773
- The All-purpose Zero||HDU5773
- hdu5773 The All-purpose Zero(DP)
- DP-HDU-5773-The All-purpose Zero
- hdu 5773 The All-purpose Zero
- HDU 5773 The All-purpose Zero
- The All-purpose Zero(喜欢这道题)
- 规章制度的处理:既要照章处理,又要考虑特殊情况
- thinking in Java test3.1练习(1)print,println,printf
- Java_io体系之BufferedWriter、BufferedReader简介、源码示例
- TDE on Oracle10.2.0.4
- I/O多路转接之epoll
- hdu5773The All-purpose Zero,1257最少拦截次数
- ajax
- hdu 3487 Play with Chain splay
- 在64位ubuntu中安装代码比较工具beyond compare
- Stage6--Python简单爬虫
- epoll详解
- Swift与OC语言中语法的一些区别
- spring 导入到eclipse
- 第9课:Scala类和对象彻底实战和Spark源码鉴赏