ZOJ3790_Consecutive Blocks
给出一个数组,最多可以删除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的更多相关文章
- 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM
刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...
- 【POJ-1390】Blocks 区间DP
Blocks Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5252 Accepted: 2165 Descriptio ...
- 开发该选择Blocks还是Delegates
前文:网络上找了很多关于delegation和block的使用场景,发现没有很满意的解释,后来无意中在stablekernel找到了这篇文章,文中作者不仅仅是给出了解决方案,更值得我们深思的是作者独特 ...
- poj 1390 Blocks
poj 1390 Blocks 题意 一排带有颜色的砖块,每一个可以消除相同颜色的砖块,,每一次可以到块数k的平方分数.问怎么消能使分数最大.. 题解 此题在徐源盛<对一类动态规划问题的研究&g ...
- Java 同步代码块 - Synchronized Blocks
java锁实现原理: http://blog.csdn.net/endlu/article/details/51249156 The synchronized keyword can be used ...
- 区块 Blocks
Structure / Blocks / Demonstrate block regions
- 使用Code::blocks在windows下写网络程序
使用Code::blocks在windows下写网络程序 作者 He YiJun – storysnail<at>gmail.com 团队 ls 版权 转载请保留本声明! 本文档包含的原创 ...
- Code::Blocks配置GTK+2和GTK+3
Code::Blocks配置GTK+2和GTK+3 作者 He YiJun – storysnail<at>gmail.com 团队 ls 版权 转载请保留本声明! 本文档包含的原创代码根 ...
- [翻译]理解Ruby中的blocks,Procs和lambda
原文出处:Understanding Ruby Blocks, Procs and Lambdas blocks,Procs和lambda(在编程领域被称为闭包)是Ruby中很强大的特性,也是最容易引 ...
随机推荐
- cookie 和session 的区别
假如我填好了淘宝的用户名密码,点击登录,浏览器客户端像服务器端发送请求,这时服务器端看这个用户是第一次登陆,session会让客户端这个浏览器生成个cookie,并给cookie一个session i ...
- 预加载 img 的方式。
原生方式: var img = new Image(); img.onerror = function() { alert('img error'); }; img.onload = function ...
- unity5.0新功能-布料、动画系统
原作者:只待苍霞 这一章讲一下布料系统, 这次的布料系统有很大的改良.Unity4中, 需要对SkinnedMeshRenderer使用SkinnedCloth, 或者对Cloth Renderer使 ...
- 【英语魔法俱乐部——读书笔记】 0 序&前沿
[英语魔法俱乐部——读书笔记] 0 序&前沿 0.1 以编者自身的经历引入“不求甚解,以看完为目的”阅读方式,即所谓“泛读”.找到适合自己的文章开始“由浅入深”的阅读,在阅读过程中就会见到 ...
- unity中三种调用其他脚本函数的方法
第一种,被调用脚本函数为static类型,调用时直接用 脚本名.函数名()第二种,GameObject.Find("脚本所在的物体的名字").SendMessage(" ...
- table 固定表头
1 .table { border-collapse: collapse; } .table th { display: table-cell; } .fixedThead {//thead disp ...
- 建筑材料系统 ASP.NET MVC4.0 + WebAPI + EasyUI + Knockout 的架构设计开发
框架介绍: 1.基于 ASP.NET MVC4.0 + WebAPI + EasyUI + Knockout 的架构设计开发 2.采用MVC的框架模式,具有耦合性低.重用性高.生命周期成本低.可维护性 ...
- 史航416第九次作业&总结
一.知识点总结: 1.二维数组定义的形式:类型名 数组名[行长度] [列长度] 例如:int a[3][2]:定义一个二维数组a,3行2列,6个元素: 2.二维数组引用的形式:类型名 数组名[行下标] ...
- cordova常用资料源
cordova的中文资料https://github.com/CordovaCn/CordovaCn 官方文档: http://cordova.apache.org/docs/en/latest/ E ...
- java序列化深拷贝
java深拷贝 序列化和反序列化合成在一起的方法CloneUtils import java.io.ByteArrayInputStream; import java.io.ByteArrayOutp ...