Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)
题目连接: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(尺取法)的更多相关文章
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...
- Codeforces Round #354 (Div. 2)
贪心 A Nicholas and Permutation #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 ...
- 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 ...
- Codeforces Round #354 (Div. 2) C. Vasya and String
题目链接: http://codeforces.com/contest/676/problem/C 题解: 把连续的一段压缩成一个数,对新的数组求前缀和,用两个指针从左到右线性扫一遍. 一段值改变一部 ...
- 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 ...
- 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 ...
- Codeforces Round #354 (Div. 2)-D
D. Theseus and labyrinth 题目链接:http://codeforces.com/contest/676/problem/D Theseus has just arrived t ...
- Codeforces Round #354 (Div. 2)-C
C. Vasya and String 题目链接:http://codeforces.com/contest/676/problem/C High school student Vasya got a ...
随机推荐
- centos解压bz2文件出错
出现的问题: 用tar 解压 tar.bz2文件出错 debian:/usr/src# tar jxf linux-2.6.26.tar.bz2tar: bzip2: Cannot exec: No ...
- C# 常用接口学习 ICollection<T>
C# 常用接口学习 ICollection<T> 作者:乌龙哈里 时间:2015-11-01 平台:Window7 64bit,Visual Studio Community 2015 参 ...
- C++笔记(to be cont'd)
最近在看这个:LearnCpp 主要是一些我自己容易忽视的地方 记一些笔记在下面,还有错漏地方请不吝赐教 CH1.10 Preprocessing The preprocessor copies th ...
- dao代码模板
提供数据源以及回收资源的工具类DbUtils: public class DbUtils { private static ComboPooledDataSource dataSource = new ...
- MAC下安装automake autoconf工具
I noticed today that while Mac OS 10.6 (specifically, 10.6.2) comes with automake and autoconf, the ...
- matlab imshow()函数显示白色图像问题
在MATLAB中,我们常使用imshow()函数来显示图像,而此时的图像矩阵可能经过了某种运算.在MATLAB中,为了保证精度,经过了运算的图像矩阵I其数据类型会从uint8型变成double型.如果 ...
- centsOS下安装vsftp的配置
1. 添加用户组 # groupadd www 2. 修改配置 # vi /etc/vsftpd/vsftpd.conf 查找: #chroot_list_enable=YES #chroot_lis ...
- php 函数积累第一天
htmlspecialchars 函数格式化表单输入的转化为html形式 exit - 输出一个消息并且退出当前脚本 list() 用一步操作给一组变量进行赋值. <?php$info = ar ...
- 丢掉鼠标-Mac神软Alfred使用手册
上篇: http://wellsnake.com/jekyll/update/2014/06/15/001/?utm_source=tuicool 下篇: http://wellsnake.com/j ...
- jquery.validate.js 无法验证隐藏域
隐藏域中的字段无法验证解决办法 修改 jquery.validate.js 中的 ignore: ":hidden",