题目链接:http://codeforces.com/contest/676/problem/C
题意:给出一个只有a,b的字符串,定义这个字符串的魅力值为“最长的连续的任意一种字符的串的长度” 你现在可以将k个字符转化 请问最大的魅力值
思路:
就枚举每个能用完k的区间就行了…
先枚举右端点,然后找到最远的用掉<=k个字符的区间
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long LL;
const int maxn = 100005;
const int inf=(1<<28)-1;
char str[maxn];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
scanf("%s",str);
int La=0,Lb=0,tmp_a=0,tmp_b=0,ans=0;
for(int i=0;i<n;++i)
{
if(str[i]=='a') tmp_b++;
else tmp_a++;
while(tmp_a>k)
{
if(str[La]=='b') tmp_a--;
La++;
}
ans=max(ans,i-La+1);
while(tmp_b>k)
{
if(str[Lb]=='a') tmp_b--;
Lb++;
}
ans=max(ans,i-Lb+1);
}
printf("%d\n",ans);
return 0;
}