[CF676C]Vasya and String(尺取法,原题)
题目链接: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(尺取法,原题)的更多相关文章
- hdu 5672 String 尺取法
String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem D ...
- POJ 3320 尺取法(基础题)
Jessica's Reading Problem Description Jessica's a very lovely girl wooed by lots of boys. Recently s ...
- hdu 5056(尺取法思路题)
Boring count Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)
题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...
- HDU 5672 String 尺取法追赶法
String Problem Description There is a string S.S only contain lower case English character.(10≤lengt ...
- poj 2566 Bound Found(尺取法 好题)
Description Signals of most probably extra-terrestrial origin have been received and digitalized by ...
- 【尺取法好题】POJ2566-Bound Found
[题目大意] 给出一个整数列,求一段子序列之和最接近所给出的t.输出该段子序列之和及左右端点. [思路] ……前缀和比较神奇的想法.一般来说,我们必须要保证数列单调性,才能使用尺取法. 预处理出前i个 ...
- codeforces #364c They Are Everywhere 尺取法
C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 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 ...
随机推荐
- mysql_fetch_row,mysql_fetch_array,mysql_fetch_assoc的区别
<?php $link=mysql_connect('localhost','root',”); mysql_select_db('abc',$link); $sql = “select * f ...
- Bluetooth
Android provides a default Bluetooth stack, BlueDroid, that is divided into two layers: The Bluetoot ...
- How does java technology relate to cloud computing?
Java Paas shootout (@IBM developer) Cloud computing is always a hot topic around IT field today.Ho ...
- Asp.net 同时下载多个文件
整理自网络 下载思路是首先把多个文件进行压缩,然后再下载压缩成的压缩包 引用文件dll:ICSharpCode.SharpZipLib.dll 1. 合成下载文件夹 Protected Sub btn ...
- Xcode Provisioning 路径
~/Library/MobileDevice/Provisioning Profiles
- 虚拟机移动后重启网络时提示Device does not seem to be present
Wmware虚拟机硬盘文件位置移动之后,重新引入到Wmware workStation中, 通过命令ifconfig...没有看到eth0..然后重启网卡 #service network resta ...
- BZOJ3473: 字符串
3473: 字符串 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 109 Solved: 47[Submit][Status] Descriptio ...
- 【HDOJ】【1693】Eat The Trees
插头DP 插头dp模板题…… 这题比CDQ论文上的例题还要简单……因为不用区分左右插头(这题可以多回路,并不是一条哈密尔顿路) 硬枚举当前位置的状态就好了>_< 题解:http://blo ...
- SqlBulkCopy 简单运用
using(SqlConnection conn = new SqlConnection(str)) { conn.Open(); using (System.Data.SqlClient.SqlBu ...
- PE文件结构详解(三)PE导出表
上篇文章 PE文件结构详解(二)可执行文件头 的结尾出现了一个大数组,这个数组中的每一项都是一个特定的结构,通过函数获取数组中的项可以用RtlImageDirectoryEntryToData函数,D ...