题目链接:http://codeforces.com/contest/676/problem/C

原题题解链接:http://www.cnblogs.com/vincentX/p/5405468.html

太菜了,昨晚光想着分块,却没考虑做尺取的时候,对于不需要变化的,那对计数器到k不做贡献。早上恍然大悟,5min改出来了…鶸一个。

 /*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f, sizeof(a))
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; const int maxn = ;
int n, k;
int a[maxn];
char s[maxn]; int main() {
// FRead();
while(~Rint(n) && ~Rint(k)) {
Rs(s+);
For(i, , n+) {
if(s[i] == 'a') a[i] = ;
else a[i] = ;
}
int l = , r = ;
int cur = , ans = ;
while() {
if(r > n) break;
while(r <= n && cur <= k) {
if(a[r] == ) {
if(cur == k) break;
cur++;
}
r++;
}
if(r - l > ans) ans = r - l;
while(l <= r && a[l] == ) l++;
cur--;
l++;
}
int ret = ans;
For(i, , n+) {
if(s[i] == 'a') s[i] = 'b';
else s[i] = 'a';
}
For(i, , n+) {
if(s[i] == 'a') a[i] = ;
else a[i] = ;
}
l = , r = ; cur = , ans = ;
while() {
if(r > n) break;
while(r <= n && cur <= k) {
if(a[r] == ) {
if(cur == k) break;
cur++;
}
r++;
}
if(r - l > ans) ans = r - l;
while(l <= r && a[l] == ) l++;
cur--;
l++;
}
printf("%d\n", max(ans, ret));
}
RT ;
}

[CF676C]Vasya and String(尺取法,原题)的更多相关文章

  1. hdu 5672 String 尺取法

    String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem D ...

  2. POJ 3320 尺取法(基础题)

    Jessica's Reading Problem Description Jessica's a very lovely girl wooed by lots of boys. Recently s ...

  3. hdu 5056(尺取法思路题)

    Boring count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  4. Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)

    题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...

  5. HDU 5672 String 尺取法追赶法

    String Problem Description There is a string S.S only contain lower case English character.(10≤lengt ...

  6. poj 2566 Bound Found(尺取法 好题)

    Description Signals of most probably extra-terrestrial origin have been received and digitalized by ...

  7. 【尺取法好题】POJ2566-Bound Found

    [题目大意] 给出一个整数列,求一段子序列之和最接近所给出的t.输出该段子序列之和及左右端点. [思路] ……前缀和比较神奇的想法.一般来说,我们必须要保证数列单调性,才能使用尺取法. 预处理出前i个 ...

  8. codeforces #364c They Are Everywhere 尺取法

    C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  9. Codeforces Round #364 (Div. 2) C. They Are Everywhere 尺取法

    C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. Windows 10 响应式设计和设备友好的开发

    使用Effective pixels有效像素设计UI 什么是缩放像素和Effective有效像素: 当你的应用程序运行在Windows的设备,系统用一个算法控制的规范,字体,和其他UI元素显示在屏幕上 ...

  2. ACCESS数据库C#操作类(包含事务)

    转自http://blog.csdn.net/allen3010/article/details/6336717 这个是针对ACCESS数据库操作的类,同样也是从SQLHELPER提取而来,分页程序的 ...

  3. Luence简单实现2

    上一篇是基于内存存储的,这次的例子是基于本地存储索引库. 上一次的代码稍微修改,代码如下: //创建词法分析器 Analyzer analyzer = new StandardAnalyzer(); ...

  4. Python编程规范

    打破一条既定规则的两个理由: 应用这个规则将导致代码可读性下降. 为了和周围的代码保持一致. 编码: 所有的 Python 脚本文件都应在文件头标上如下标识或其兼容格式的标识: # -*- codin ...

  5. mysql 的物理结构

    mysql 的物理结构 跟着小辉老师学来的mysql知识,由于本人记性不好,但又觉得它很重要故把它记了下来,方便自己以后回忆,也希望能对大家有所帮助. 以下内容来自 小辉 老师的mysql教程,和部分 ...

  6. IDENTITY属性使用

    转自:http://www.cnblogs.com/seusoftware/p/3804333.html 一. 获取IDENTITY列值插入了数据,有时还需要获取刚才生成的序列值另作他用,返回给前端也 ...

  7. 【C# 反射泛型】

    C# 反射泛型 摘自:http://www.itwis.com/html/net/c/20110411/10175.html C#泛型反射和普通反射的区别,泛型反射和普通反射的区别就是泛型参数的处理上 ...

  8. 将LINUX变成路由器

    将LINUX变成路由器 2009-06-04 22:38:45 标签:LINUX 路由器 休闲 职场 版权声明:原创作品,如需转载,请与作者联系.否则将追究法律责任.     LINUX系统是一个强大 ...

  9. Node.js 4.0.0:灵雀云和 OneAPM 的整合测试

    关于 Node.js 4.0.0 稳定版刚刚推出,备受期待,迫不及待地想用它写点东西:此外,要把 Demo 放到 Internet 上得有一个公网 IP ,看到灵雀云挺不错的而且提供域名解析,简直业界 ...

  10. 深入理解Tornado——一个异步web服务器

    本人的第一次翻译,转载请注明出处:http://www.cnblogs.com/yiwenshengmei/archive/2011/06/08/understanding_tornado.html原 ...