给出一个数组,最多可以删除k个数,问能够获得的最长的一个数字连续段为多少?

把所有相同的数字都提取出来,保存取得每个数字需要删除的数字,然后二分枚举就可以了。

召唤代码君:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define maxn 500200
using namespace std; int a[maxn],b[maxn],first[maxn],next[maxn];
int Q[maxn],top,f[maxn];
bool vis[maxn];
int n,k,N,ans; void go(int cur)
{
vis[cur]=true;
if (next[cur]!=-){
go(next[cur]);
Q[top++]=cur-next[cur]-;
}
else Q[top++]=;
} int main()
{
while (scanf("%d%d",&n,&k)!=EOF){
for (int i=; i<n; i++){
scanf("%d",&a[i]);
b[i]=a[i];
}
sort(b,b+n);
N=unique(b,b+n)-b;
for (int i=; i<n; i++) a[i]=lower_bound(b,b+N,a[i])-b+;
memset(first,-,sizeof(int)*(n+));
for (int i=; i<n; i++) next[i]=first[a[i]],first[a[i]]=i;
memset(vis,false,sizeof(bool)*(n+));
ans=;
for (int i=n-; i>=; i--)
if (!vis[i]){
top=;
go(i);
for (int j=; j<top; j++) Q[j]+=Q[j-];
for (int pos=; pos<top; pos++){
if (Q[top-]-Q[pos]<=k){
ans=max(ans,top-pos);
break;
} int l=pos,r=top-,mid;
while (l<r){
mid=(l+r+)/;
if (Q[mid]-Q[pos]>k) r=mid-;
else l=mid;
}
ans=max(ans,l-pos+);
}
}
printf("%d\n",ans);
}
return ;
}

ZOJ3790_Consecutive Blocks的更多相关文章

  1. 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM

    刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...

  2. 【POJ-1390】Blocks 区间DP

    Blocks Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5252   Accepted: 2165 Descriptio ...

  3. 开发该选择Blocks还是Delegates

    前文:网络上找了很多关于delegation和block的使用场景,发现没有很满意的解释,后来无意中在stablekernel找到了这篇文章,文中作者不仅仅是给出了解决方案,更值得我们深思的是作者独特 ...

  4. poj 1390 Blocks

    poj 1390 Blocks 题意 一排带有颜色的砖块,每一个可以消除相同颜色的砖块,,每一次可以到块数k的平方分数.问怎么消能使分数最大.. 题解 此题在徐源盛<对一类动态规划问题的研究&g ...

  5. Java 同步代码块 - Synchronized Blocks

    java锁实现原理: http://blog.csdn.net/endlu/article/details/51249156 The synchronized keyword can be used ...

  6. 区块 Blocks

    Structure / Blocks / Demonstrate block regions

  7. 使用Code::blocks在windows下写网络程序

    使用Code::blocks在windows下写网络程序 作者 He YiJun – storysnail<at>gmail.com 团队 ls 版权 转载请保留本声明! 本文档包含的原创 ...

  8. Code::Blocks配置GTK+2和GTK+3

    Code::Blocks配置GTK+2和GTK+3 作者 He YiJun – storysnail<at>gmail.com 团队 ls 版权 转载请保留本声明! 本文档包含的原创代码根 ...

  9. [翻译]理解Ruby中的blocks,Procs和lambda

    原文出处:Understanding Ruby Blocks, Procs and Lambdas blocks,Procs和lambda(在编程领域被称为闭包)是Ruby中很强大的特性,也是最容易引 ...

随机推荐

  1. RequireJS 基础(一)

    RequireJS由James Burke创建,他也是AMD规范的创始人. RequireJS会让你以不同于往常的方式去写JavaScript,你将不再使用script标签在HTML中引入JS文件,以 ...

  2. CSS中如何让元素隐藏

    在CSS中,让元素隐藏(指屏幕范围内肉眼不可见)的方法很多,有的占据空间,有的不占据空间:有的可以响应点击,有的不能响应点击.下面一个个列出,选一个适合你的 { display: none; /* 不 ...

  3. RadGrid使用技巧:从RadGrid获取绑定的值

    本文主要介绍从RadGrid获取绑定的值,仅适用于Telerik RadControls for asp.net ajax. 获取方式 RadGrid把绑定的值存储在VIewState中,即使View ...

  4. windbg学习---.browse打开一个新的command 窗口

    .browse r eax .browse <command>将会显示新的命令浏览窗口和运行给出的命令

  5. java.lang.IllegalStateException: Couldn't read row 1, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data fr

    Android中操作Sqlite遇到的错误:java.lang.IllegalStateException: Couldn't read row 1, col 0 from CursorWindow. ...

  6. sscanf与正则表达式(转)

    今天翻google reader的时候看到这样一篇文章,介绍的是sscanf的高级用法.直到今天我才知道sscanf是可以直接用正则表达式的,惭愧. 在msdn中sscanf的声明如下 int ssc ...

  7. Android中webview和js之间的交互(转)

    http://www.cnblogs.com/leizhenzi/archive/2011/06/29/2093636.html 1.android中利用webview调用网页上的js代码. Andr ...

  8. hdu 3307 Description has only two Sentences (欧拉函数+快速幂)

    Description has only two SentencesTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...

  9. TOMCAT的安装部署配置(配图解)

    TOMCAT的安装部署配置 前提已经成功搭建配置JDK 下载好压缩包后,直接解压至某一目录下,目录中不能包含中文 双击安装文件,出现如下界面 点击[NEXT],出现如下界面 点击[I AGREE],出 ...

  10. 《锋利的jQuery》(第2版)读书笔记4

    第9章 jQuery Mobile jQuery Mobile是用来填补jQuery在移动设备应用上的缺憾的一个新项目. 它基于jQuery框架并使用HTML5和CSS3这些新的技术,除了能提供很多基 ...