The All-purpose Zero

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1097    Accepted Submission(s): 271

Problem Description
?? gets an sequence S with n intergers(0 < n <= 100000,0<= S[i] <= 1000000).?? has a magic so that he can change 0 to any interger(He does not need to change all 0 to the same interger).?? wants you to help him to find out the length of the longest increasing (strictly) subsequence he can get.
Input
The first line contains an interger T,denoting the number of the test cases.(T <= 10)
For each case,the first line contains an interger n,which is the length of the array s.
The next line contains n intergers separated by a single space, denote each number in S.
Output
For each test case, output one line containing “Case #x: y”(without quotes), where x is the test case number(starting from 1) and y is the length of the longest increasing subsequence he can get.
Sample Input
2 7 2 0 2 1 2 0 5 6 1 2 3 3 0 0
Sample Output
Case #1: 5 Case #2: 5

Hint

In the first case,you can change the second 0 to 3.So the longest increasing subsequence is 0 1 2 3 5.

题意:有一个序列,含有n个数,序列中的0可以变成任意数,问你变换完后最长上升子序列的长度是多少

显然在最后面的0可以作为最长上升子序列的元素,那么前面的0怎么变换呢,思路是这样的:把0去掉,做LIS 为了保证是添上0变换的数字后是上升的,把每个非0数减去前面包含的0的个数,然后len加上0的个数即可

样例一 2 0 2 1 2 0 5 -> 2 (0) 1 0 1 (0) 3 新序列是 2 1 0 1 3 去掉了两个0,新序列LIS=3

那么原序列LIS=3+2 =5;

#include <stdio.h>
#include <iostream>
#include <stdlib.h>using namespace std;
const int inf=0x3f3f3f3f,maxn=1e5+10;
int a[maxn],c[maxn],len;
int find(int R,int x)
{int L=1,mid;while(L<=R){mid=(L+R)/2;if(c[mid]==x)return mid;else if(c[mid]<=x)L=mid+1;else R=mid-1;}return L;
}int main()
{int n,m,T=1,t;int sum,j,zero,tot;scanf("%d",&t);while(t--){scanf("%d",&n);sum=0;tot=0;int x;for(int i=1;i<=n;i++){scanf("%d",&x);if(x==0)sum++;elsea[tot++]=x-sum;}if(tot==0){printf("Case #%d: %d\n",T++,n);continue;}len=0;c[0]=-inf;for(int i=0;i<tot;i++){if(a[i]>c[len])j=++len;elsej=find(len,a[i]);c[j]=a[i];}/*for(int i=1;i<=len;i++)cout<<c[i]<<" ";cout<<endl;*/printf("Case #%d: %d\n",T++,len+sum);}
}

hdu5773 --2016多校第四场1010相关推荐

  1. 2019牛客多校第四场 I题 后缀自动机_后缀数组_求两个串de公共子串的种类数

    目录 求若干个串的公共子串个数相关变形题 对一个串建后缀自动机,另一个串在上面跑同时计数 广义后缀自动机 后缀数组 其他:POJ 3415 求两个串长度至少为k的公共子串数量 @(牛客多校第四场 I题 ...

  2. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

  3. 牛客多校第四场【B-Basic Gcd Problem】

    牛客多校第四场[B-Basic Gcd Problem] 题目链接:https://ac.nowcoder.com/acm/contest/5669/B 思路:先要理解公式,多看几个数据基本就会有点想 ...

  4. 2022 年牛客多校第四场补题记录

    A Task Computing 题意:给定长度为 nnn 的序列 {(wi,pi)}\{(w_i,p_i)\}{(wi​,pi​)},从中选出 mmm 项并重新排列得到子序列 {a1,a2,⋯,am ...

  5. 20190731杭电多校第四场

    1001 AND Minimum Spanning Tree(Solved By jlz/cys) 贪心. 对于每个数,找二进制形式下末尾连续1的数量,若为i,则可连到数字2^(i-1),若2^(i- ...

  6. hdu2852(2009多校第四场) 树状数组求区间第k大的数 两种方法

    二分查找n*logn*logn 比较容易理解 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm& ...

  7. hdu2846(2009多校第四场) 字典树

    明明就是个简单的字典树,我不过就是想复习一下尼玛被自己坑死了T^T 把字符串分解那儿写错了,检查了半天没找到错误,然后以为被卡数组内存,难过的学习字典树的指针写法.. 发现还是不对,大半夜突然看到自己 ...

  8. hdu 4639 2013多校第四场 hehe Fibonacci 数列,组合计数,字符串处理

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4639 题目思路: 首先我们取出所有he这样的东西,考察连续的k个"he"串,通过找 ...

  9. 杭电多校第四场-H- K-th Closest Distance

    题目描述 You have an array: a1, a2, , an and you must answer for some queries. For each query, you are ...

  10. 2014多校第四场1006 || HDU 4902 Nice boat (线段树 区间更新)

    题目链接 题意 : 给你n个初值,然后进行两种操作,第一种操作是将(L,R)这一区间上所有的数变成x,第二种操作是将(L,R)这一区间上所有大于x的数a[i]变成gcd(x,a[i]).输出最后n个数 ...

最新文章

  1. Making Your Own iPhone Frameworks. In Xcode
  2. Ajax的优缺点以及异步和同步的区别
  3. 傅里叶变换函数FFT的使用方法
  4. 使用python matplotlib画图
  5. 文件字符串变量插入linux,Linux Shell脚本实现在文件指定的行插入字符串
  6. 一文带你了解目前的“光伏母亲公路” 能照明充电和融雪
  7. 一个简易Android购物App的开发
  8. python bmp转jpg
  9. ERNIE: Enhanced Representation through Knowledge Integration, Yu Sun 2020【representation+Bert+ner】
  10. 【python安装】错误——“User installations are disabled via policy on the machine”
  11. 深信服2019届校园招聘专场(私聊博主得内推码,免简历筛选)
  12. 【单词辨析】technology,technique,skill 技术技能
  13. Docker——阿里云镜像加速
  14. asp毕业设计——基于asp+access的学生成绩查询系统设计与实现(毕业论文+程序源码)——成绩查询系统
  15. 高考招生计划数据采集系统设计
  16. Photoshop学习(四):为图像添加文字
  17. msi微星B350M主板开启VT(Virtualization Technology)
  18. FTP文件夹打开错误,Windows无法访问此文件夹
  19. js反斜杠\替换成正斜杠/
  20. 实习生转正答辩成长和收获_监督实习生的公司的5点收获

热门文章

  1. Django出现Error: 111 connect to 192.168.158.141:22122. Connection refused
  2. 电磁屏蔽一般可分为三种
  3. Excel 行列转换的最简方法 1
  4. jQ知识补全(供已经入门jq开发者)
  5. XP系统计算机桌面图标不见,xp如何显示桌面图标?windows xp系统桌面图标消失的解决方法...
  6. android 放大镜功能,Android放大镜效果实现
  7. 再读德鲁克#3 从管理外包人员到全面质量管理
  8. 代码审计系列:审计思路学习笔记
  9. 宝塔php伪静态规则,宝塔BT面板伪静态规则大全汇总
  10. 紫外线测光仪的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告