Codeforces Round #354 (Div. 2) C. Vasya and String 尺取
2016-06-01 18:46
323 查看
题目大意:
给你一个只含‘a’ ‘ b ’ 的字符串,问不超过k次替换(‘a’换成‘b’,‘b’换成‘a’)可以产生的
最长连续且字符都相同的子串的长度是多少。“裸的”尺取。
给你一个只含‘a’ ‘ b ’ 的字符串,问不超过k次替换(‘a’换成‘b’,‘b’换成‘a’)可以产生的
最长连续且字符都相同的子串的长度是多少。“裸的”尺取。
#include<bits/stdc++.h> using namespace std; const int maxn=100005; char s[maxn]; int a[maxn]; int n,k; int work(){ int s=0,t=0,ans=0; int cnt=0; while( s<=t ){ while( cnt<=k &&t<n ){ if( a[t]==0 ){ cnt++; } if(cnt<=k) ans=max( ans,t-s+1 ); t++; } if( a[s]==0 )cnt--; s++; } return ans; } int main() { scanf("%d%d",&n,&k); scanf("%s",s); for(int i=0;i<n;i++){ a[i]=s[i]-'a'; } int ans1=work(); for(int i=0;i<n;i++)a[i]=a[i]?0:1; int ans2=work(); printf("%d\n",max(ans1,ans2)); return 0; }
相关文章推荐
- CodeForces 624D Array GCD
- hdu 5700 区间交
- csu:1956: 数字和 (多指针尺取)
- HDU 5815 Golden Week
- 51nod 1686 第K大区间(二分 尺取)
- poj 2100 Graveyard Design(尺取)
- poj 2739 Sum of Consecutive Prime Numbers(尺取,暴力)
- CodeForces 616D Longest k-Good Segment(尺取)
- poj 3320 Jessica's Reading Problem(尺取)
- poj 3061 Subsequence(尺取)
- 计蒜客 微软的员工福利
- 2017多校联合第六场1008/hdu 6103
- ACM常用的解题技巧:尺取法
- hdu 6119/2017百度之星初赛B——小小粉丝度度熊(尺取/贪心)
- poj 3320 - Jessica's Reading Problem (尺取)
- SDUT 2017 Autumn Single Contest O 周六场个人赛
- 2017ccpc哈尔滨 hdu 6231 B k-th number 题解 二分答案+尺取法
- HDU 6103 枚举 +尺取
- poj 2100 Graveyard Design
- poj 2379 (快速建立素数表+尺取法)