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 ...
随机推荐
- php有些系统会报错或提示 Cannot modify header information - headers already sent by
Warning: Cannot modify header information - headers already sent by (output started at /home/test/do ...
- 对于oracle监听器的配置
oracle 的 net configuration assist中配置完第一项的监听程序配置(对应文件listener.ora)之后,还要重新配置下第三项本地网络服务名配置(对应文件tnsname ...
- UVa 11174 (乘法逆元) Stand in a Line
题意: 有n个人排队,要求每个人不能排在自己父亲的前面(如果有的话),求所有的排队方案数模1e9+7的值. 分析: <训练指南>上分析得挺清楚的,把公式贴一下吧: 设f(i)为以i为根节点 ...
- UVa 1648 (推公式) Business Center
题意: 有一种奇怪的电梯,每次只能向上走u个楼层或者向下走d个楼层 现在有m个这种电梯,求恰好n次能够到达的最小楼层数(必须是正数),最开始默认位于第0层. 分析: 假设电梯向上走x次,则向下走n-x ...
- 实现一个简单的FTP服务器(十四)
此为一个网络编程的一个系列,后续会把内容补上...
- 我是红领巾,分享2014 google不能用的方法。
那啥已经20天打不开了. 得爬qiang. 今天无意间发现一个好东东. 特记录一下. 360浏览器设置 1. 工具菜单==>选项==>高级设置==>管理搜索引擎 . 2. ...
- Java [Leetcode 168]Excel Sheet Column Title
题目描述: Given a positive integer, return its corresponding column title as appear in an Excel sheet. F ...
- noip2006提高组题解
第一题:能量项链 区间型动态规划 据说这题在当年坑了很多人. f(i, j) 表示从第i个珠子开始合并j个珠子所释放的最大能量. f(i, j) = max{ f(i, k} + f(i+k, j-k ...
- dbms_stats.gather_table_stats与analyze table 的区别[转贴]
Analyze StatementThe ANALYZE statement can be used to gather statistics for a specific table, index ...
- Using Open Source Static Libraries in Xcode 4
Using Open Source Static Libraries in Xcode 4 Xcode 4.0.1 allows us to more easily create and use th ...