Gym - 100712B 预处理暴力
2017-05-07 22:02
260 查看
题意:
A是固定出的, Rock for the first Xrounds, Paper for the next Yrounds, andScissors for the last Zrounds.,加起来为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;
}
相关文章推荐
- Gym 100531D Digits (暴力)
- Gym 100637F F. The Pool for Lucky Ones 暴力
- Codeforces Gym 100203G G - Good elements 标记暴力
- Codeforces Gym 100002 C "Cricket Field" 暴力
- Codeforces 769D k-Interesting Pairs Of Integers【思维+预处理+暴力枚举】
- Gym 100712H(边双联通+树的直径)
- Codeforces Gym 100637G G. #TheDress 暴力
- Gym - 100703G-G-Game of numbers-暴力
- Codeforces Gym 100418B 暴力
- 北航校赛 更大公约数(预处理+暴力,好题)
- Gym 100712H(边双联通+树的直径)
- Restore Points Gym - 101498M dfs暴力搜
- Gym - 100203A Ariel 暴力+位运算
- GYM - 100812J Feeling of Comradeship (暴力)
- GYM 100712 I.Bahosain and Digits(枚举)
- HackerRank - pairs-again(暴力+预处理)
- 【HDU5482】Numquam vincar,暴力(da biao)预处理+组合数
- Codeforces 106D Treasure Island 预处理前缀和+暴力(水
- XTUOJ1247 Pair-Pair 预处理+暴力
- Gym 100712H(边双联通+树的直径)