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. 初遇Git与MarkDown 文件

    新年好! 昨晚熬夜在学Git,稍微会了一些命令. 推荐大家去try.github.io上学习,这是GitHub提供的网页,它在网页提供了一个“伪”模拟器,根据网页的提示学习命令.网页上说15分钟就能学 ...

  2. Android创建启动画面

    每一个Android应用启动之后都会出现一个Splash启动界面,显示产品的LOGO.公司的LOGO或者开发人员信息.假设应用程序启动时间比較长,那么启动界面就是一个非常好的东西,能够让用户耐心等待这 ...

  3. VS插件开发——格式化变量定义语句块

    插件介绍 代码地址:https://github.com/sun2043430/vs2008_format_variable_define_plugin/ 在vs里,对选中的变量定义块进行格式化,效果 ...

  4. iOS中的图像处理(二)——卷积运算

    关于图像处理中的卷积运算,这里有两份简明扼要的介绍:文一,文二. 其中,可能的一种卷积运算代码如下: - (UIImage*)applyConvolution:(NSArray*)kernel { C ...

  5. 我写的一个 Qt 显示图片的控件

    Qt 中没有专门显示图片的控件.通常我们会使用QLabel来显示图片.可是QLabel 显示图片的能力还是有点弱.比方不支持图像的缩放一类的功能.使用起来不是非常方便. 因此我就自己写了个简单的类. ...

  6. USACO Palindromic Squares 【STL__string_的应用】

    这里有个讲解 string 用法非常详细的博文:https://www.byvoid.com/zhs/blog/cpp-string 题目意思很简单啦,就是找回文 使用string可以高速A过 Sou ...

  7. Asp.Net Core

    开源Asp.Net Core小型社区系统 源码地址:Github 前言 盼星星盼月亮,Asp.Net Core终于发布啦!! Asp.Net发布时我还在上初中,没有赶上.但是Asp.Net Core我 ...

  8. 区间重合判断(pojg校门外的树)

    pojg:http://poj.grids.cn/practice/2808 解法1:以空间换时间: #include<stdio.h> #include<string.h> ...

  9. awk内置变量 awk有许多内置变量用来设置环境信息,这些变量可以被改变,下面给出了最常用的一些变量。

    ARGC 命令行参数个数 ARGV 命令行参数排列 ENVIRON 支持队列中系统环境变量的使用 FILENAME awk浏览的文件名 FNR 浏览文件的记录数 FS 设置输入域分隔符,等价于命令行 ...

  10. jquery插件讲解:轮播(SlidesJs)+验证(Validation)

    SlidesJs(轮播支持触屏)——官网(http://slidesjs.com) 1.简介 SlidesJs是基于Jquery(1.7.1+)的响应幻灯片插件.支持键盘,触摸,css3转换. 2.代 ...