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

原题题解链接:http://www.cnblogs.com/vincentX/p/5405468.html

太菜了,昨晚光想着分块,却没考虑做尺取的时候,对于不需要变化的,那对计数器到k不做贡献。早上恍然大悟,5min改出来了…鶸一个。

 /*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f, sizeof(a))
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; const int maxn = ;
int n, k;
int a[maxn];
char s[maxn]; int main() {
// FRead();
while(~Rint(n) && ~Rint(k)) {
Rs(s+);
For(i, , n+) {
if(s[i] == 'a') a[i] = ;
else a[i] = ;
}
int l = , r = ;
int cur = , ans = ;
while() {
if(r > n) break;
while(r <= n && cur <= k) {
if(a[r] == ) {
if(cur == k) break;
cur++;
}
r++;
}
if(r - l > ans) ans = r - l;
while(l <= r && a[l] == ) l++;
cur--;
l++;
}
int ret = ans;
For(i, , n+) {
if(s[i] == 'a') s[i] = 'b';
else s[i] = 'a';
}
For(i, , n+) {
if(s[i] == 'a') a[i] = ;
else a[i] = ;
}
l = , r = ; cur = , ans = ;
while() {
if(r > n) break;
while(r <= n && cur <= k) {
if(a[r] == ) {
if(cur == k) break;
cur++;
}
r++;
}
if(r - l > ans) ans = r - l;
while(l <= r && a[l] == ) l++;
cur--;
l++;
}
printf("%d\n", max(ans, ret));
}
RT ;
}

[CF676C]Vasya and String(尺取法,原题)的更多相关文章

  1. hdu 5672 String 尺取法

    String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem D ...

  2. POJ 3320 尺取法(基础题)

    Jessica's Reading Problem Description Jessica's a very lovely girl wooed by lots of boys. Recently s ...

  3. hdu 5056(尺取法思路题)

    Boring count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  4. Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)

    题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...

  5. HDU 5672 String 尺取法追赶法

    String Problem Description There is a string S.S only contain lower case English character.(10≤lengt ...

  6. poj 2566 Bound Found(尺取法 好题)

    Description Signals of most probably extra-terrestrial origin have been received and digitalized by ...

  7. 【尺取法好题】POJ2566-Bound Found

    [题目大意] 给出一个整数列,求一段子序列之和最接近所给出的t.输出该段子序列之和及左右端点. [思路] ……前缀和比较神奇的想法.一般来说,我们必须要保证数列单调性,才能使用尺取法. 预处理出前i个 ...

  8. codeforces #364c They Are Everywhere 尺取法

    C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  9. Codeforces Round #364 (Div. 2) C. They Are Everywhere 尺取法

    C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. 微软职位内部推荐-Senior SDE for Win Shell Exp

    微软近期Open的职位: Job posting title: Senior Software Development Engineer Location: China, Beijing Divisi ...

  2. google api , the problem of null refresh token

    http://stackoverflow.com/questions/10827920/google-oauth-refresh-token-is-not-being-received The ref ...

  3. 解决在ubuntu下requests 无法找到模块packages

    我明明用pip install requests安装成功了,但是依然报下面的错 错误1 requests.packages.urllib3.disable_warnings()AttributeErr ...

  4. 利用Vagrant搭建多平台环境

    Vagrant 是一个创建和分发虚拟化开发环境的工具,使用ruby编写,本身并不包含虚拟机管理软件,因此我们需要配合Vagrant安装一个虚拟机软件.Vagrant支持VMware, Virtual ...

  5. 来吧,给你的Winform列表控件画个妆

    前言 以前看别人的控件好看只有羡慕的份:以前觉得控件重绘是个很复杂的东西:以前知道MSDN很全面很专业却一直没有好好用起来: 作为初级程序猿,不能原地踏步,来吧,让我们一起把 TreeView 美化一 ...

  6. C# 延迟初始化

    一个对象的延迟初始化意味着该对象的创建将会延迟至第一次使用该对象时.(在本主题中,术语“延迟初始化”和“延迟实例化”是同义词.)延迟初始化主要用于提高性能,避免浪费计算,并减少程序内存要求. 以下是最 ...

  7. JQuery,UIbootstrap风格弹出层

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <met ...

  8. linux挂载windwos共享文件

    mount -t cifs -o useaname=***,password=*** //172.16.82.32/test /mnt username,password分别为windows那边允许共 ...

  9. PHP之cookie相关实例教程与经典代码

    ·php 中cookie和session的用法比较 ·php会话控制cookie与Session会话处理 ·php中利用cookie实现购物车实例 ·php中cookie与session应用学习笔记 ...

  10. VC6.0环境安装STLport-5.2.1

    今天安装STLport,网上搜资料安装好久,都不行,因为STLport 的版本不对,我这是STLport-5.2.1新版本. (注意:下面的步骤都在一个cmd里操作,很简单的原因:环境变量啊) 1.首 ...