设 LGR
存在数量为
x
x
x,CSP
存在数量为
y
y
y。
很明显,我们只需要将其中数量较小的一方改没就行了(一个巴掌拍不响)。
每两个字符串可同意进行一次更改,答案为:
⌈ min ( x , y ) 2 ⌉ \left\lceil\frac{\min(x,y)}{2}\right\rceil ⌈2min(x,y)⌉
实现
#include<bits/stdc++.h>
using namespace std;
#define int long long
int t;
string s;
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
for(cin>>t;t;t--){
cin>>s;
int _LGR=0,_CSP=0;
for(int i=2;i<s.size();i++){
if(s[i-2]=='L'&&s[i-1]=='G'&&s[i]=='R'){
_LGR++;
}else if(s[i-2]=='C'&&s[i-1]=='S'&&s[i]=='P'){
_CSP++;
}
}
cout<<(min(_LGR,_CSP)+1)/2<<'\n';
}
return 0;
}