Gym 100712B Rock-Paper-Scissors

来源:互联网 发布:软件销售好做吗 编辑:程序博客网 时间:2024/06/07 19:20

题目链接:http://codeforces.com/gym/100712/attachments


先将前n次都出石头、剪刀、布的获胜次数预处理一下,然后分三段枚举一下即可。


附上AC代码:


#include <bits/stdc++.h>//#pragma comment(linker, "/STACK:102400000, 102400000")using namespace std;const int maxn = 1005;char op[maxn];int r[maxn], s[maxn], p[maxn];int n;int main(){#ifdef LOCALfreopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);#endifint T;scanf("%d", &T);while (T--){scanf("%d", &n);scanf("%s", op);for (int i=1; i<=n; ++i){r[i] = r[i-1]+(op[i-1]=='R' ? 0 : (op[i-1]=='S' ? 1 : -1));s[i] = s[i-1]+(op[i-1]=='S' ? 0 : (op[i-1]=='P' ? 1 : -1));p[i] = p[i-1]+(op[i-1]=='P' ? 0 : (op[i-1]=='R' ? 1 : -1));}//for (int i=0; i<=n; ++i)//printf("%d %d %d\n", r[i], s[i], p[i]);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[n]-s[j] > 0)++ans;printf("%d\n", ans);}return 0;}


1 0
原创粉丝点击