Gym

https://vjudge.net/problem/Gym-100712B

题意:

石头剪刀布游戏。

给出一个玩家n局的出的顺序,现在另一个是这样出的,X+Y+Z=n,在前X轮出石头,中间Y轮出布,最后Z轮出剪刀,问有多少种方法可以赢。

思路:
预处理。

对玩家出的顺序进行处理,用R[i]表示第i位及之前所出现的石头总数,同理P[i],s[i]。

然后二重循环枚举,将n分为3段的两个断点,判断在这种情况下是谁赢,统计次数即可。

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<vector>
 6 #include<stack>
 7 #include<queue>
 8 #include<cmath>
 9 #include<map>
10 using namespace std;
11 
12 char str[1005];
13 int R[1005],P[1005],S[1005];
14 
15 int main()
16 {
17     //freopen("D:\input.txt","r",stdin);
18     int T,n;
19     scanf("%d",&T);
20     while(T--)
21     {
22         scanf("%d",&n);
23         scanf("%s",str+1);
24         R[0]=P[0]=S[0]=0;
25         for(int i=1;i<=n;i++)
26         {
27             R[i]=R[i-1];
28             P[i]=P[i-1];
29             S[i]=S[i-1];
30             if(str[i]=='R')  R[i]++;
31             else if(str[i]=='P')  P[i]++;
32             else S[i]++;
33         }
34         int ans=0;
35         for(int x=0;x<=n;x++)
36         {
37             for(int y=x;y<=n;y++)
38             {
39                 int f1=S[x]-S[0]+R[y]-R[x]+P[n]-P[y];
40                 int f2=P[x]-P[0]+S[y]-S[x]+R[n]-R[y];
41                 if(f1>f2)  ans++;
42             }
43         }
44         printf("%d
",ans);
45     }
46     return 0;
47 }
原文地址:https://www.cnblogs.com/zyb993963526/p/6812588.html