ZOJ 3790 Consecutive Blocks 模拟题
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 模拟题的更多相关文章
- 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 ...
- ZOJ 3790 Consecutive Blocks
大致题意就是给你一个数列,让你最多移除K个数字,使得连续的相同数字的长度最大,并求出最大长度. 我们将此序列按颜色排序,颜色相同的话按位置排序,那么排完序之后颜色相同的blocks就在一起,只是他们的 ...
- ZOJ 3790 Consecutive Blocks (离散化 + 暴力)
题目链接 虽然是一道暴力的题目,但是思路不好想.刚开始还超时,剪枝了以后1200ms,不知道为什么还是这么慢. 题意:给你n个点,每个点有一种颜色ci,给你至多k次删除操作,每次删除一个点,问最多k次 ...
- ZOJ 3818 Pretty Poem 模拟题
这题在比赛的时候WA到写不出来,也有判断ABC子串不一样不过写的很差一直WA 在整理清思路后重写一遍3Y 解题思路如下: 第一种情况:ABABA. 先判断开头的A与结尾的A,得到A的长度, 接着判断A ...
- Capture the Flag ZOJ - 3879(模拟题)
In computer security, Capture the Flag (CTF) is a computer security competition. CTF contests are us ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- ZOJ1111:Poker Hands(模拟题)
A poker deck contains 52 cards - each card has a suit which is one of clubs, diamonds, hearts, or sp ...
- Codeforces Beta Round #7 B. Memory Manager 模拟题
B. Memory Manager 题目连接: http://www.codeforces.com/contest/7/problem/B Description There is little ti ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
随机推荐
- SSL证书与Https应用部署小结
为了提高网站的安全性,一般会在比较敏感的部分页面采用https传输,比如注册.登录.控制台等.像Gmail.网银等全部采用https传输. https/ssl 主要起到两个作用:网站认证.内容加密传输 ...
- 动态规划 最长公共子序列 LCS,最长单独递增子序列,最长公共子串
LCS:给出两个序列S1和S2,求出的这两个序列的最大公共部分S3就是就是S1和S2的最长公共子序列了.公共部分 必须是以相同的顺序出现,但是不必要是连续的. 选出最长公共子序列.对于长度为n的序列, ...
- UItexfile实时验证输入字符
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementS ...
- win7 ShuipFCMS 配置 及问题
随风下载地址:http://www.shuipfcms.com/download.shtml 碰到问题: 一.mb_strlen 函数不支持 到php.ini 开启 ;extension=php ...
- (Problem 2)Even Fibonacci numbers
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting w ...
- QTableWidget的用法总结
在使用Qt不多的日子里,已经两次用到了QTableWidget这个控件,也慢慢的习惯和喜欢上了它.再使用QTableWidget的时候,已不像刚开始使用时的迷茫.嗯嗯.现在就来总结总结我与QTable ...
- eclipse 找不到application选项
处理如下:Window-Preferences-Run/Debug-Perspectives 中的 And Build修改为如下
- 2、Zookeeper集群搭建、命令行Client操作
zookeeper 集群最好是奇数台: 5台允许挂掉2台 4台只能允许挂掉1台 zjtest7-redis:/opt/zookeeper/bin# ./zkServer.sh status ZooKe ...
- What’s New in Python 2.7 — Python 3.4.0b2 documentation
What's New in Python 2.7 - Python 3.4.0b2 documentation What's New in Python 2.7¶
- Linux环境下编译并执行ava helloworld程序
原文:http://blog.lupaworld.com/home-space-uid-24466-do-blog-id-2578.html 已经学会怎样在Windows下怎样编辑,编译和运行Java ...