题目链接: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 ;
}

最新文章

  1. 关于分工的思考 (Thoughts on Division of Labor)
  2. Start with connect by prior 递归查询
  3. Distributed Databases and Data Mining: Class timetable
  4. Android——PULL解析XML
  5. java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
  6. -_-#【HTML】同一个标签页打开
  7. UVAlive 6131 dp+斜率优化
  8. Dalvik虚拟机的启动过程分析
  9. C#使用Xamarin开发可移植移动应用(3.Xamarin.Views控件)附源码
  10. golang 二进制转十进制实现方式
  11. Python开发【第十篇】:模块
  12. 自学elastic search
  13. python 中爬虫 content和text的区别
  14. gridcontrol 添加行删除行
  15. jQuery对标签select优化:实现模糊搜索查询功能
  16. Android四大组件应用系列——使用BroadcastReceiver和Service实现倒计时
  17. 安装git工具在ubuntu系统
  18. 奇怪吸引子---Coullet
  19. Retrofit三步理解之中的一个 ------------------ Retrofit的简单使用总结
  20. linux--GCC简单用法

热门文章

  1. .NET4.5中WCF中默认生成的basicHttpsBinding的研究
  2. IOS开发问题录:如何在Swift中引入Head文件?
  3. iOS10 配置须知-b
  4. 典型的js页面
  5. Python Socket File Transfer
  6. JavaScript string array 数组
  7. Document Set 【一】
  8. 3157: 国王奇遇记 &amp; 3516: 国王奇遇记加强版 - BZOJ
  9. 剑指offer--面试题17
  10. JavaScript高级---桥模式设计