hdu5773 --2016多校第四场1010
来源:互联网 发布:pymongo 遍历大量数据 编辑:程序博客网 时间:2024/06/01 12:23
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.
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
272 0 2 1 2 0 561 2 3 3 0 0
Sample Output
Case #1: 5Case #2: 5HintIn 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++; else a[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; else j=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); }}
0 0
- hdu5773 --2016多校第四场1010
- (多校第四场1010)HDU5773 The All-purpose Zero(LIS)
- hdu5773(2016多校第四场,最长上升子序列n*logn变形)
- (多校第五场1003)HDU5773 Divide the Sequence
- 多校第四场
- 多校第四场
- (2016多校联赛)HDU5773 The All-purpose Zero
- 2016多校联合第四场 HDU5768
- 2016多校第四场 HDU5769
- 2016多校训练赛第4场第十题(hdu5773——The All-purpose Zero) (简单)
- 2013 多校第四场
- 多校联赛第四场
- hdu5774(2016多校第四场,水题)
- hdu 5769 Substring 2016 多校第四场
- 2016多校训练Contest4: 1010 The All-purpose Zero hdu5773
- 2012多校第四场总结
- 2013多校联合训练第四场
- hdu 4639 Hehe 多校第四场
- 用 webView 加载 html 字符串代码来显示图片
- 集合框架_03_List集合之Vector(线程安全)
- SDUT OJ 3363 数据结构实验之图论七:驴友计划
- sed命令的用法
- C/C++求职宝典21个重点笔记(常考笔试面试点)
- hdu5773 --2016多校第四场1010
- Android 四大大图片缓存(Imageloader,Picasso,Glide,Fresco)原理、特性对比
- 学习coroutine
- 使用Linq查询感觉好方便的说
- 用php操作消息隊列,RabbitMQ消息队列在PHP下的应用大全
- 四道裸最小生成树
- POJ 3057 二分图匹配 + dinic
- 二分查找递归和非递归
- Windows XP Service Packv2.0中文简体版