Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E
给你n个数,每个数代表一种颜色,给你1到m的m种颜色。最多可以删k个数,问你最长连续相同颜色的序列的长度是多少。
将相同颜色的下标存到对应颜色的容器中,比如ans[a[i]].push_back(i)就是将下标为i颜色为a[i]的数存到ans[a[i]]容器中。
对于每种颜色序列,尺取一下 在差距小于k的情况下取能取到的最大长度。
//#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = 1e5 + ;
vector <int> ans[N];
int a[N*]; int solve(int u, int k) {
int len = ans[u].size(), notcnt = , cnt = , l = , res = ;
//notcnt表示中间删除数的多少,cnt表示颜色为u的序列的长度
for(int i = ; i < len; ++i) {
int v = ans[u][i];
notcnt += v - ans[u][i - ] - ;
cnt++;
while(notcnt > k && l <= i) {
notcnt -= ans[u][l + ] - ans[u][l] - ;
cnt--;
l++;
}
res = max(cnt, res);
}
return res;
} int main()
{
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
for(int i = ; i <= n; ++i) {
scanf("%d", a + i);
ans[a[i]].push_back(i);
}
int res = ;
for(int i = ; i <= m; ++i) {
if(ans[i].size()) { //要是存在颜色为i的数
res = max(res, solve(i, k));
}
}
printf("%d\n", res);
return ;
}
Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)的更多相关文章
- codeforces水题100道 第十八题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table (brute force)
题目链接:http://www.codeforces.com/problemset/problem/509/A题意:f[i][1]=f[1][i]=1,f[i][j]=f[i-1][j]+f[i][j ...
- Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song 算贡献+前缀和
E. Pretty Song time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table【递推】
A. Maximum in Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 贪心 Codeforces Round #289 (Div. 2, ACM ICPC Rules) B. Painting Pebbles
题目传送门 /* 题意:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles, 使得任意两个piles,用颜色c填充的pebbles数量 ...
- 递推水题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table
题目传送门 /* 模拟递推水题 */ #include <cstdio> #include <iostream> #include <cmath> #include ...
- Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)
排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typede ...
- Codeforces Round #354 (Div. 2)——C. Vasya and String(尺取)
C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules)
Codeforces Round #116 (Div. 2, ACM-ICPC Rules) 代码 Codeforces Round #116 (Div. 2, ACM-ICPC Rules) A. ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...
随机推荐
- dp,px转换
public static int dip2px(Context context, float dpValue) { final float scale = context.getRes ...
- IIS Web负载均衡的几种方式
Web负载均衡的几种实现方式 摘要:负载均衡(Load Balance)是集群技术(Cluster)的一种应用.负载均衡可以将工作任务分摊到多个处理单元,从而提高并发处理能力.目前最常见的负载均衡应用 ...
- 试图从数据库 ‘UFData_001_2003' 中提取的逻辑页 (1:10720) 属于对象 '0',而非对象 'syscolumns'
数据库可以使用,可以备份,但对备份进行恢复时报错,使用sp_attach_db对两个物理文件进行连接时,报同样错误: 服务器: 消息 605,级别 21,状态 1,行 1 试图从数据库 ‘UFData ...
- Nginx - webbench压力测试
1. 下载,安装,进目录. 2. 执行:webbench -t 10 -c 1000 http://192.168.1.44/ (我开的nginx,默认端口80,直接处理了) 结果分析: Webben ...
- h.264码流解析_一个SPS的nalu及获取视频的分辨率
00 00 00 01 67 42 00 28 E9 00 A0 0B 77 FE 00 02 00 03 C4 80 00 00 03 00 80 00 00 1A 4D 88 10 94 0 ...
- HWM的实验
HWM是数据段中使用空间和未使用空间之间的界限,假如现有自由链表上的数据块不能满足需求,Oracle把HWM指向的数据块加入到自由链表上,HWM向前移动到下一个数据块.简单说,一个数据段中,HWM左边 ...
- 《C++ Primer 4th》读书笔记 第8章-标准IO库
原创文章,转载请注明出处:http://www.cnblogs.com/DayByDay/p/3936457.html
- 【转】开始iOS 7中自动布局教程(一)
原文网址:http://www.cocoachina.com/industry/20131203/7462.html 原文:Beginning Auto Layout Tutorial in iOS ...
- .net-C#代码判断
ylbtech-doc:.net-C#代码判断 C#代码判断 1.A,C#代码判断返回顶部 01.{ C#题目}public static void Main(string[] args){ ...
- Spring+iBatis+Atomikos实现JTA事务
Atomikos是一个公司名字,旗下最著名的莫过于其Atomikos的事务管理器产品. 产品分两个:一个是开源的TransactionEssentials,一个是商业的ExtremeTransacti ...