The topic probably says to a string consisting of a and B, which can change up to K characters, and ask how long the longest consecutive and identical string can be obtained by changing it.
Use the ruler, change to a and change to B to do once: double pointer I and j,j non-stop +, and then if you encounter the need to change and change the number of times to let i++ correct the number of changes, and finally update the answer. Time complexity O (n).
Also, note the situation of the k=0.
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Charstr[111111];6 intMain () {7 intn,k;8scanf"%d%d%s",&n,&k,str);9 intI=0, j=0, tmpn=0, tmpk=0, ans=0;Ten while(j<N) { One if(str[j]=='a'){ A++TMPN; -}Else if(k==0){ -tmpn=0; the}Else{ - while(tmpk==k) { - if(str[i]=='b'){ ---TMPK; + } ---TMPN; +++i; A } at++TMPK; -++TMPN; - } -ans=Max (ANS,TMPN); -++J; - } inI=0; j=0; tmpn=0; tmpk=0; - while(j<N) { to if(str[j]=='b'){ +++TMPN; -}Else if(k==0){ thetmpn=0; *}Else{ $ while(tmpk==k) {Panax Notoginseng if(str[i]=='a'){ ---TMPK; the } +--TMPN; A++i; the } +++TMPK; -++TMPN; $ } $ans=Max (ANS,TMPN); -++J; - } theprintf"%d", ans); - return 0;Wuyi}
Codeforces 676C Vasya and String (ruler)