炒鸡煎蛋的题解
2025-05-10 14:57:24
发布于:四川
0阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int func(int x){
int cnt = 0;
char a = s[x], b = s[x + 1];
for(int i = x; i >= 0; i--){
if(s[i] == a || s[i] == 'w') cnt++;
else break;
}
for(int i = x + 1; i <= 3 * n; i++){
if(s[i] == b || s[i] == 'w') cnt++;
else break;
}
return cnt;
}
int main(){
cin >> n >> s;
s = s + s + s;
int cnt = 0;
for(int i = n + 1; i <= 2 * n; i++){
if(s[i] == 'w'){
s[i] = 'r';
cnt = max(cnt, func(i));
s[i] = 'b';
cnt = max(cnt, func(i));
s[i] = 'w';
}
cnt = max(cnt, func(i));
}
cnt = min(cnt, n);
cout << cnt;
return 0;
}
这里空空如也
有帮助,赞一个