problemCode=3790">Consecutive Blocks

先离散一下,然后模拟,把一种颜色i所在的位置都放入G[i]中。然后枚举一下终点位置,滑动窗体使得起点和终点间花费不超过K,求中间过程的最大值就可以。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define N 100005
set<int>myset;
map<int,int>mp;
set<int>::iterator p;
int n ,k;
int a[N];
vector<int>s[N];
int go(int cur){
int now = k;
int ans = 1, l = 0, siz = s[cur].size();
int len = 1;
for(int i = 1; i < siz; i++){
if(s[cur][i-1] == s[cur][i]-1)
{
len++;
ans = max(ans, len);
continue;
}
now -= s[cur][i]-s[cur][i-1]-1;
if(now>=0)
{ len++; ans = max(ans, len);}
else
{
while(now<0)
{
l++;
now += s[cur][l]-s[cur][l-1]-1;
len--;
}
len++;
}
}
return ans;
}
int main()
{
int T ,m,u,v,w, i ,j;
while(~scanf("%d %d",&n,&k)){
myset.clear();
mp.clear();
for(i=1;i<=n;i++)scanf("%d",&a[i]),myset.insert(a[i]);
for(p=myset.begin(), i = 1; p!=myset.end(); p++, i++)
mp.insert(pair<int,int>(*p,i)),s[i].clear();
int top = i;
for(i=1;i<=n;i++)
{
a[i] = mp.find(a[i])->second;
s[a[i]].push_back(i);
}
int ans = 0;
for(i=1;i<top;i++)
ans = max(ans, go(i));
printf("%d\n",ans);
}
return 0;
}
/*
13 3
1000000000 2 2 1 1 2 2 5 6 8 2 2 2 */

ZOJ 3790 Consecutive Blocks 模拟题的更多相关文章

  1. zoj 3790 Consecutive Blocks 离散化+二分

    There are N (1 ≤ N ≤ 105) colored blocks (numbered 1 to N from left to right) which are lined up in ...

  2. ZOJ 3790 Consecutive Blocks

    大致题意就是给你一个数列,让你最多移除K个数字,使得连续的相同数字的长度最大,并求出最大长度. 我们将此序列按颜色排序,颜色相同的话按位置排序,那么排完序之后颜色相同的blocks就在一起,只是他们的 ...

  3. ZOJ 3790 Consecutive Blocks (离散化 + 暴力)

    题目链接 虽然是一道暴力的题目,但是思路不好想.刚开始还超时,剪枝了以后1200ms,不知道为什么还是这么慢. 题意:给你n个点,每个点有一种颜色ci,给你至多k次删除操作,每次删除一个点,问最多k次 ...

  4. ZOJ 3818 Pretty Poem 模拟题

    这题在比赛的时候WA到写不出来,也有判断ABC子串不一样不过写的很差一直WA 在整理清思路后重写一遍3Y 解题思路如下: 第一种情况:ABABA. 先判断开头的A与结尾的A,得到A的长度, 接着判断A ...

  5. Capture the Flag ZOJ - 3879(模拟题)

    In computer security, Capture the Flag (CTF) is a computer security competition. CTF contests are us ...

  6. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  7. ZOJ1111:Poker Hands(模拟题)

    A poker deck contains 52 cards - each card has a suit which is one of clubs, diamonds, hearts, or sp ...

  8. Codeforces Beta Round #7 B. Memory Manager 模拟题

    B. Memory Manager 题目连接: http://www.codeforces.com/contest/7/problem/B Description There is little ti ...

  9. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

随机推荐

  1. 设计模式总结1--observer pattern

    <!-- 设计模式 --><!--是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了可重用代码.让代码更容易被他人理解.保证代 码可靠性 --&g ...

  2. 动态规划 最长公共子序列 LCS,最长单独递增子序列,最长公共子串

    LCS:给出两个序列S1和S2,求出的这两个序列的最大公共部分S3就是就是S1和S2的最长公共子序列了.公共部分 必须是以相同的顺序出现,但是不必要是连续的. 选出最长公共子序列.对于长度为n的序列, ...

  3. ASP.NET CS文件中输出JavaScript脚本

    ClientScript.RegisterStartupScript:http://msdn.microsoft.com/zh-cn/library/system.web.ui.clientscrip ...

  4. Android:源码环境下移植第三方的apk内置到ROM(System Image)中

    1. 首先在vendor目录下新建一个the3rdapk的目录,将需要内置的apk丢进去,目录名自己随意定. 2. 在 build/target/product/common.mk最后面,在$(cal ...

  5. iOS系统自带的 UIAlertView 自动旋转的实现

    这里主要解析 UIAlertView 的几个关键功能的实现: 随着设备屏幕的旋转而旋转: Alert弹出框,使用UIWindow来实现,就是说,不用依赖于当前显示在最前面的UIView. 实现源码参考 ...

  6. HDU OJ 5326 Work( 2015多校联合训练第3场) 并查集

    题目连接:戳ME #include <iostream> #include <cstdio> #include <cstring> using namespace ...

  7. Palindromes _easy version

    Palindromes _easy version Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  8. windows下apache+wsgi+web.py环境搭建

    首先安装好wsgi模块并启用:1.下载地址:我本机是python2.7 http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi- ...

  9. spring-mvc关键点掌握 high level

    在本例中,我们将使用Spring MVC框架构建一个入门级web应用程序.Spring MVC 是Spring框架最重要的的模块之一.它以强大的Spring IoC容器为基础,并充分利用容器的特性来简 ...

  10. jquery ajax json 数据的遍历

    需求:进行ajax请求后,后台传递回来以下json数据 { "data":[ {","name":"选择A","valu ...