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 ...
随机推荐
- Windows Phone 8初学者开发—第3部分:编写第一个Windows Phone 8应用程序
原文 Windows Phone 8初学者开发—第3部分:编写第一个Windows Phone 8应用程序 原文地址: http://channel9.msdn.com/Series/Windows- ...
- Logback相关知识汇总
例如:%-4relative 表示,将输出从程序启动到创建日志记录的时间 进行左对齐 且最小宽度为4格式修饰符,与转换符共同使用:可选的格式修饰符位于“%”和转换符之间.第一个可选修饰符是左对齐 标志 ...
- 学校作业-Usaco DP水题
好吧,因为USACO挂掉了,所以我写的所有代码都不保证正确性[好的,这么简单的题,再不写对,你就可以滚粗了! 第一题是USACO 2.2.2 ★Subset Sums 集合 对于从 1 到 N 的连 ...
- IT忍者神龟之Java动态代理与CGLib代理
<br>public class UserDAOImpl{ <br><br> public void save() { <br> / ...
- linux修改shell为zsh
以前使用的bash,如果目录很长,那么整个路径都被占满了. 询问一下一位大牛,答曰:zsh. 安装:ubuntu下sudo apt-get install zsh 修改默认登录shell: $chsh ...
- javascript 学习随笔1
html部分 <body onload="message()"><!--主题部分加载就调用-->document.getElementById(" ...
- ZOJ 3211 Dream City DP 01背包 经典问题
题目大意:JAVAMAN 到梦幻城市旅游见到了黄金树,黄金树上每天回结出金子.已经有n棵树,JAVAMAN要停留m天,每天只能砍掉一棵树,砍掉树后就能得到树上的黄金.给定n棵树上原有的黄金a[i]和每 ...
- Codeforces 479D - Long Jumps
479D - Long Jumps, 480B - Long Jumps It , or . If we can already measure both x and y, output . Then ...
- 进入MFC讲坛的前言(四)
MFC的消息映射机制 MFC的设计者们在设计MFC时,紧紧把握一个目标,那就是尽可能使得MFC的代码要小,速度尽可能快.为了这个目标,他们使用了许多技巧,其中很多技巧体现在宏的运用上,实现MFC的消息 ...
- Android 多分辨率机适应
如果你有一台机器,如以下决议: 800 x 480 1024 x 600 1024 x 768 1280 x 800 1920 x 1200 2048 x 1536 总共六种类分辨率机器,假设依照dp ...