题目连接: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. ip地址分类和网段区分

    IP地址分类/IP地址10开头和172开头和192开头的区别/判断是否同一网段 简单来说在公司或企业内部看到的就基本都是内网IP,ABC三类IP地址里的常见IP段. 每个IP地址都包含两部分,即网络号 ...

  2. we are happy 把空格换成 %20 剑指offer P44

    public class StringReplace { public static void replaceSpace(String[] str, int length) { if(str == n ...

  3. mongodb 性能提高之利用索引, 待续

    > 10 , 用户无法忍受 >1s , 需要加装中提示 数据库对软件整体影响是不言而喻的, 那么使用 MOngoDB时 该如何提高数据库性能 第一: 索引, 相当于记忆法的 地点桩 1. ...

  4. jenkins自动部署war包到jetty

    1.把jenkins.war包复制到jetty的webapps下面 2.在jetty的webapps下面新建jenkins.xml文件 内容如下: <?xml version="1.0 ...

  5. 《JavaScript高级程序设计》读书笔记 ---理解对象

    上一章曾经介绍过,创建自定义对象的最简单方式就是创建一个Object 的实例,然后再为它添加属性和方法,如下所示.var person = new Object();person.name = &qu ...

  6. scala正则表达式

       正则表达式     Scala 通过 scala.util.matching 包种的 Regex 类来支持正则表达式 scala.util.matching.Regex.构造一个Regex对象, ...

  7. JS 阻止整个网页的内容被选中

    pretty-girl { -webkit-user-select: none; } 可是!可是!不是每个浏览器都可以不忧桑!!!那就只能请脚本大王出山了. 阻止选中 有时候,我们需要禁止用户选中一些 ...

  8. 简单的Android之apk包反编译方法

    网上相关的文章一大堆了,我只是总结下自己的反编译方法和工具 工具下载地址: http://download.csdn.net/detail/zsjangel/7104663 下载上面的三个工具的压缩包 ...

  9. 真实代理(RealProxy)在WCF中的运用

    在WCF中,当我们在调用服务端的方法时,一般有两点需要考虑:1.捕获服务端的异常信息,记录日志:2.及时关闭会话信道,当调用超时或调用失败时及时中断会话信道.我们一般会像下面这样处理(以Calcula ...

  10. C#.NET的微信功能开发学习

    对于新手的我来说,我不是申请一个微信公众号认证后进行开发,我是申请一个订阅号,然后通过自己申请的订阅号的公众平台测试号来学习. 一,申请后成功后,打开开发者工具-公众平台测试号 二,进去公众平台测试号 ...