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. elk 搭建

    elk 平台搭建: ELK平台搭建 系统环境 System: Centos release 6.7 (Final) ElasticSearch: 2.1.0 Logstash: 2.1.1 Kiban ...

  2. 统计单词频率--map

    问题描述: 输入一个单词列表,每行一个单词,统计单词出现的频率 思路: 主要是使用c++中的map容器.map实质上是一个二叉查找树,可以做到插入.删除.查询,平均查询时间在O(logn).n为map ...

  3. Sicily-1024

    一. 题意: 有n个节点,n-1条边,并且任意两个节点都连通.模拟一下,实际上是一棵树的便利,求从特定根节点出发最长路径的值.这里用了广搜. 二. 每个节点只有两条邻接边,每个节点用一个vector来 ...

  4. hdu1698 Just a Hook 线段树:成段替换,总区间求和

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 Problem ...

  5. SRBF Lighting

     SRBF的全称是Spherical Radial Basis Function,笔者擅自翻译为球面放射基底函数.由于SRBF并不怎么出名,相对来说,SH(Spherical Harmonic)球 ...

  6. android 实现蓝牙自动配对连接

    BluetoothConnectActivityReceiver.java:监听蓝牙配对的广播 代码: package com.imte.Broadcast; import com.imte.util ...

  7. cacti气象图调整(批量位置调整、更改生成图大小等)

    cacti气象图能够非常直观的看到各个节点的流量.这里用的是CactiEZ中文版 V10 1.调整气象图大小 默认有一个1024像素的背景图可选, 这里我们须要新增一个1600像素的背景图. 背景图自 ...

  8. 【QT相关】类头文件解读、QT编辑模式、读取text文本

    Wizard产生的头文件类包含了必须的#include文件.构造函数.析构函数和UI对象: #include <QMainWindow> namespace Ui {class Notep ...

  9. BZOJ 2242: [SDOI2011]计算器( 快速幂 + 扩展欧几里德 + BSGS )

    没什么好说的... --------------------------------------------------------------------- #include<cstdio&g ...

  10. input file 在开发中遇到的问题 类似ajax form表单提交 input file中的文件

    最近在做项目的过程中遇到个问题,在这里做个记录防止日后忘记 现今的主流浏览器由于ajax提交form表单无法把文件类型数据提交到后台,供后台处理,可是开发中由于某些原因又不得不用ajax提交文件, 为 ...