题目连接: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. jQuery 源码学习(先放在这,未开始)

    希望对源码有一个框架上认识,对整体结构有一个理解. 对外只暴露出了一个变量,$/jQuery,这个变量指向一个函数 function(a,b){return new n.fn.init(a,b)}

  2. python安装pip

    pip类似RedHat里面的yum,安装Python包非常方便.本节详细介绍pip的安装.以及使用方法. 1.pip下载安装 1.1 pip下载 # wget "https://pypi.p ...

  3. 记一次-angular-数字格式化

    一个收费功能模块,需要做数据验证. input标签的ng-model的数据格式化 <input type="number" class="form-control& ...

  4. PHP中 post 与get的区别 详细说明

    1.Get 方法通过 URL 请求来传递用户的数据,将表单内各字段名称与其内容,以成对的字符串连接,置于 action 属性所指程序的 url 后,如[url]http://www.jincaib.c ...

  5. Hdu 3363 Ice-sugar Gourd(对称,圆)

    Ice-sugar Gourd Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  6. sublime从官网纯净版到插件完整版

    01.纯净版下载地址:www.sublimetext.com/ 02.下载Package Control插件管理工具,网址:https://packagecontrol.io/ 安装介绍:https: ...

  7. screen实现关闭ssh之后继续运行代码

    本文基于Ubuntu 14.04 使用SSH连接远程服务器,启动服务,退出SSH后,服务也就终止了,使用Screen可以解决这个问题. 1.安装Screen apt-get install scree ...

  8. mysql导出数据表结构,必须退出mysql命令.重新使用msyqldump命令

    只导出数据库中所有表结构(-d 减去数据) 导出所有表结构和数据 mysqldump -uroot --default-character-set=utf8 -p123-d必须空格good>H: ...

  9. submit 防止重复提交 --禁止提交

    <form action="/apply/apply" method="POST" id="indentForm"> <p ...

  10. 5、Struts2自定义拦截器

    一.拦截器相关知识 1.Struts2框架剖析 Holly版本生活案例: 影视公司(拍电影)    ActionMapper 传媒公司(包装明星) ActionMapping 明星           ...