rock-paper-scissors
维护三个前缀和,然后注意顺序,最后做差来确定可行的答案,因为答案比较小,可以考虑这种暴力做法,像这种方案数可以++的题真的不多,如果想不出来特别优秀的想法,不妨简单化思维
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 100010
#define For(i,a,b) for(int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
int R[],S[],P[];
int n,m;
int T;
char a[];
int cnt;
void in(int &x){
int y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(int x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
}
int main(){
in(T);
while(T--){
cnt=;
in(n);
cin>>(a+);
For(i,,n){
if(a[i]=='R'){
R[i]=R[i-];
S[i]=S[i-]-;
P[i]=P[i-]+;
}
if(a[i]=='S'){
R[i]=R[i-]+;
S[i]=S[i-];
P[i]=P[i-]-;
}
if(a[i]=='P'){
R[i]=R[i-]-;
S[i]=S[i-]+;
P[i]=P[i-];
}
}
For(i,,n)
For(j,,n)
if(i+j<=n&&R[i]+P[i+j]-P[i]+S[n]-S[j+i]>)
cnt++;
o(cnt);p('\n');
}
return ;
}