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

题意:一串字符串,最多改变k次,求最大的相同子串

题解:很明显直接尺取法

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<functional>
#define cl(a,b) memset(a,b,sizeof(a));
#define FFC(i,a,b) for(int i=a;i<=b;++i)
#define pb push_back
#define LL long long
#define dbg puts("ok")
#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;
char a[];
int main(){
int n,k;
while(~scanf("%d%d",&n,&k)){
scanf("%s",a);
int l=,r=,ans=,ca=,cb=,tmp=;
while(r<n){
while(r<n&&tmp<=k){
if(a[r]=='a')ca++;else cb++;
tmp=min(ca,cb);
r++;
}
if(r==n&&tmp<=k){ans=max(r-l,ans);break;}
r--;if(a[r]=='a')ca--;else cb--;tmp=min(ca,cb);
ans=max(r-l,ans);
while(a[l]==a[l+]){if(a[l]=='a')ca--;else cb--;l++,tmp=min(ca,cb);}
if(a[l]=='a')ca--;else cb--;l++,tmp=min(ca,cb);
}
printf("%d\n",ans);
}
return ;
}

Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)的更多相关文章

  1. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  2. 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

    题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...

  3. Codeforces Round #354 (Div. 2)

    贪心 A Nicholas and Permutation #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 ...

  4. Codeforces Round #354 (Div. 2) C. Vasya and String 二分

    C. Vasya and String 题目连接: http://www.codeforces.com/contest/676/problem/C Description High school st ...

  5. Codeforces Round #354 (Div. 2) C. Vasya and String

    题目链接: http://codeforces.com/contest/676/problem/C 题解: 把连续的一段压缩成一个数,对新的数组求前缀和,用两个指针从左到右线性扫一遍. 一段值改变一部 ...

  6. 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 ...

  7. Codeforces Round #354 (Div. 2)-C. Vasya and String,区间dp问题,好几次cf都有这种题,看来的好好学学;

    C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #354 (Div. 2)-D

    D. Theseus and labyrinth 题目链接:http://codeforces.com/contest/676/problem/D Theseus has just arrived t ...

  9. Codeforces Round #354 (Div. 2)-C

    C. Vasya and String 题目链接:http://codeforces.com/contest/676/problem/C High school student Vasya got a ...

随机推荐

  1. Chloe and pleasant prizes

    Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  2. nginx构建https

    1.生成证书#openssl genrsa -des3 -out server.key 1024#openssl req -new -key server.key -out server.csr#op ...

  3. C# 常用接口学习 IEnumerable<T>

    作者:乌龙哈里 时间:2015-10-24 平台:Window7 64bit,Visual Studio Community 2015 本文参考: MSDN IEnumerable<T> ...

  4. UI_APPEARANCE_SELECTOR 延伸

    iOS后属性带UI_APPEARANCE_SELECTOR 可以统一设置全局作用 例如: 1>开关控件 @property(nullable, nonatomic, strong) UIColo ...

  5. Github朝花夕拾

    删除fork的项目   下载指定revision的repository 通过git log查看提交历史,最好是GUI查看 然后执行命令git reset –hard <sha1> 同步到最 ...

  6. linux jdk环境变量

    export JAVA_HOME=/usr/share/jdk8 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/ ...

  7. js--面向对象继承

    Object.create()方法可以传入一个原型对象,并创建一个基于该原型的新对象,但是新对象什么属性都没有. // 原型对象: var Student = { name: 'Robot', hei ...

  8. iOS二维码条形码的制作

    - (IBAction)creatQRImage:(id)sender { [self.textField resignFirstResponder]; //这里是我放了个TextField的控件,但 ...

  9. PyConChina2016 北京站 献给Python开发者

    开源编程语言Python近年来在互联网.游戏.云计算.大数据.运维.企业软件等领域有非常多的应用.今天小编就为大家推荐一场Python开发者的盛会:PyConChina2016(北京)! PyCon大 ...

  10. JS复习:第六章

    创建对象 一.工厂模式 function createPerson(name,age,job){ var o = new Object(); o.name = name; o.age = age; o ...