您的位置:首页 > 其它

Gym - 100712B 预处理暴力

2017-05-07 22:02 260 查看




题意:

A是固定出的, Rock for the first X​rounds, Paper for the next Y​rounds, andScissors for the last Z​rounds.,加起来为n,每个大于等于0.

给出B的出拳,问怎么赢:

思路:

直接枚举的话需要三段0~i,i~j,j~n三重有超时风险。这里预处理,把三种出法的n次情况全部存在数组里。

然后最后判断r[i]+p[j]-p[i]+s
-s[j] > 0即可。p[j]减去超重的p[i]得到二段,s
减去s[j]得到第三段

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
string str;
int r[maxn], s[maxn], p[maxn];
int n;

int main(){
// freopen("in.txt","r",stdin);
int T;
cin>>T;
while (T--){
cin>>n;
cin>>str;
for (int i=1; i<=n; ++i){
r[i] = r[i-1]+(str[i-1]=='R' ? 0 : (str[i-1]=='S' ? 1 : -1));
s[i] = s[i-1]+(str[i-1]=='S' ? 0 : (str[i-1]=='P' ? 1 : -1));
p[i] = p[i-1]+(str[i-1]=='P' ? 0 : (str[i-1]=='R' ? 1 : -1));
}
int ans = 0;
for (int i=0; i<=n; ++i)
for (int j=i; j<=n; ++j)
if (r[i]+p[j]-p[i]+s
-s[j] > 0)
ans++;
cout<<ans<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: