HDOJ 5773 The All-purpose Zero
来源:互联网 发布:歪歪mac版 编辑:程序博客网 时间:2024/06/04 23:35
题目链接:HDOJ5773
官方题解已经写的很详细了:题解是1010
题目中需要注意的是:如果全是0,答案是n,在枚举的时候要特判
然后为了避免0干扰,把原数组所有的0删除,构建一个新的非0数组,其值为原数组的值减去当前位置之前的零的数量
用O(nlogn)求得LIS之后,加上0的数量,就是最终结果
代码为:
#include <cstdio>#include <algorithm>using namespace std;const int maxn=1e5+50;int t,n,a[maxn],b[maxn],ans[maxn];int cnt,zero,len=1;int main(){//freopen("input.txt","r",stdin);scanf("%d",&t);for(int Case=1;Case<=t;Case++){scanf("%d",&n);cnt=zero=0;for(int i=1;i<=n;i++){scanf("%d",&a[i]);if (a[i]==0) zero++;else b[cnt++]=a[i]-zero;}if (zero==n){printf("Case #%d: %d\n",Case,n);continue;}ans[0]=b[0];len=1;for(int i=1;i<cnt;i++)if (b[i]>ans[len-1]) ans[len++]=b[i];else{int pos=lower_bound(ans,ans+len,b[i])-ans;ans[pos]=b[i];}printf("Case #%d: %d\n",Case,zero+len);}return 0;}
0 0
- HDOJ 5773 The All-purpose Zero(LIS)
- hdoj 5773 The All-purpose Zero
- HDOJ 5773 The All-purpose Zero
- HDOJ 5773 The All-purpose Zero
- HDOJ-----5773The All-purpose Zero(LIS)
- The All-purpose Zero
- The All-purpose Zero
- The All-purpose Zero
- The All-purpose Zero
- DP-HDU-5773-The All-purpose Zero
- hdu 5773 The All-purpose Zero
- HDU 5773 The All-purpose Zero
- HDU 5773 The All-purpose Zero lis
- hdu 5773 The All-purpose Zero
- HDU 5773 The All-purpose Zero
- 多校4 The All-purpose Zero 5773
- hdu 5773 (The All-purpose Zero)
- HDU-5773-The All-purpose Zero
- POJ1185——炮兵阵地(状态压缩dp)
- (转载)使用Xcode7的Instruments检测解决iOS内存泄露
- Weblogic报java.lang.OutOfMemoryError: PermGen space
- hdu 5783 Divide the Sequence
- Chef 的安装与使用
- HDOJ 5773 The All-purpose Zero
- jQuery源码研究分析学习笔记-jQuery.extend()、jQuery.fn.extend()(八)
- 统计函数三点注意
- 坚持#第3天~递归呀我多么爱你
- java继承
- ReviewForJob——堆排序
- Android面试题1
- Beego源码解析-(三)-HTTP请求处理流程
- shell 将字符串作为变量名并打印