Codeforce - Rock-Paper-Scissors
Rock-Paper-Scissors is a two-player game, where each player chooses one of Rock, Paper, or Scissors. Here are the three cases in which a player gets one point:
Choosing Rock wins over a player choosing scissors.
Choosing Scissors wins over a player choosing Paper.
Choosing Paper wins over a player choosing Rock.
In all other cases, the player doesn’t get any points.
Bahosain and his friend Bayashout played N rounds of this game. Unlike Bayashout, Bahosain was too lazy to decide what to play next for each round, so before starting to play, he chose three integers X Y Z such that X+Y+Z = N and X, Y, Z ≥ 0, and then played Rock for the first X rounds, Paper for the next Y rounds, and Scissors for the last Z rounds.
Bayashout got more points in the N rounds and won. Given the moves played by Bayashout in each round, Bahosain wants to know the number of ways in which he could have chosen X, Y and Z such that he wins in the N rounds.
The winner of the N rounds is the player that gets more total points in the N rounds.
Input
The first line of input contains T (1 ≤ T ≤ 64), where T is the number of test cases.
The first line of each test case contains an integer N (1 ≤ N ≤ 1000) that represents the number of rounds.
The next line contains a string of N uppercase letters, the first letter represents the choice of Bayashout for the first round, the second letter represents his choice for the second round, and so on.
Each letter in the string is one of the following: R (Rock), P (Paper), or S (Scissors).
Output
For each test case, print a single line with the number of ways in which Bahosain could have won.
|
Sample Input |
Sample Output |
|
4 |
3 |
|
3 |
1 |
|
RPS |
1 |
|
1 |
5 |
|
R |
|
|
5 |
|
|
PPRSR |
|
|
5 |
|
|
RPSPR |
这道题刚才我居然用递归去做,做了好久写了一个递归出来,结果是递归只能过样例,真是惨不忍睹的结局,哎,看看别人的方法,前缀和,多好,用三个数组表示前i局出不同手势的得分
最后来统计,不过统计的时候注意区间的划分,在最后统计的时候最好自己画个图,这样就很清晰了,画个区间图,还有要注意的是这题的出拳顺序是有规定的,必须是RPS,这样的顺序
就是说R在P前面,P在S前面
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
using namespace std; #define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 const int MX = 1111;
int r[MX], p[MX], s[MX]; void ini() {
memset(r, 0, sizeof(r));
memset(p, 0, sizeof(p));
memset(s, 0, sizeof(s));
} //使用前缀和处理问题
int main() {
//freopen("input.txt", "r", stdin);
int n;
char str[MX];
int cas;
while (scanf("%d", &cas) != EOF) {
while (cas--) {
ini();
scanf("%d %s", &n, str + 1);
for (int i = 1; i <= n; i++) {
if (str[i] == 'R') {
r[i] = r[i - 1];
p[i] = p[i - 1] + 1;
s[i] = s[i - 1] - 1;
} else if (str[i] == 'P') {
r[i] = r[i - 1] - 1;
p[i] = p[i - 1];
s[i] = s[i - 1] + 1;
} else {
r[i] = r[i - 1] + 1;
p[i] = p[i - 1] - 1;
s[i] = s[i - 1];
}
}
int ans = 0;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
if (r[i] + p[i + j] - p[i] + s[n] - s[i + j] > 0) {
ans++;
}
}
}
printf("%d\n", ans);
}
}
return 0;
}
Codeforce - Rock-Paper-Scissors的更多相关文章
- 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)
2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...
- SDUT 3568 Rock Paper Scissors 状压统计
就是改成把一个字符串改成三进制状压,然后分成前5位,后5位统计, 然后直接统计 f[i][j][k]代表,后5局状压为k的,前5局比和j状态比输了5局的有多少个人 复杂度是O(T*30000*25*m ...
- FFT(Rock Paper Scissors Gym - 101667H)
题目链接:https://vjudge.net/problem/Gym-101667H 题目大意:首先给你两个字符串,R代表石头,P代表布,S代表剪刀,第一个字符串代表第一个人每一次出的类型,第二个字 ...
- Gym - 101667H - Rock Paper Scissors FFT 求区间相同个数
Gym - 101667H:https://vjudge.net/problem/Gym-101667H 参考:https://blog.csdn.net/weixin_37517391/articl ...
- Gym101667 H. Rock Paper Scissors
将第二个字符串改成能赢对方时对方的字符并倒序后,字符串匹配就是卷积的过程. 那么就枚举字符做三次卷积即可. #include <bits/stdc++.h> struct Complex ...
- 【题解】CF1426E Rock, Paper, Scissors
题目戳我 \(\text{Solution:}\) 考虑第二问,赢的局数最小,即输和平的局数最多. 考虑网络流,\(1,2,3\)表示\(Alice\)选择的三种可能性,\(4,5,6\)同理. 它们 ...
- 题解 CF1426E - Rock, Paper, Scissors
一眼题. 第一问很简单吧,就是每个 \(\tt Alice\) 能赢的都尽量让他赢. 第二问很简单吧,就是让 \(\tt Alice\) 输的或平局的尽量多,于是跑个网络最大流.\(1 - 3\) 的 ...
- HDOJ(HDU) 2164 Rock, Paper, or Scissors?
Problem Description Rock, Paper, Scissors is a two player game, where each player simultaneously cho ...
- HDU 2164 Rock, Paper, or Scissors?
http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...
- 1090-Rock, Paper, Scissors
描述 Rock, Paper, Scissors is a classic hand game for two people. Each participant holds out either a ...
随机推荐
- EF – 3.EF数据查询基础(下)数据关联
5.5.1 <关于“数据关联”,你不一定清楚的事> 这讲视频比较全面地介绍了“一对一”.“一对多”和“多对多”三种数据关联类型在关系数据库和Entity Framework数据模型中的实现 ...
- c# 扩展方法奇思妙用基础篇八:Distinct 扩展(转载)
转载地址:http://www.cnblogs.com/ldp615/archive/2011/08/01/distinct-entension.html 刚看了篇文章 <Linq的Distin ...
- Android中Service 使用详解(LocalService + RemoteService)
Service 简介: Service分为本地服务(LocalService)和远程服务(RemoteService): 1.本地服务依附在主进程上而不是独立的进程,这样在一定程度上节约了资源,另外L ...
- OCJP(1Z0-851) 模拟题分析(七)-->214
Exam : 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 以下分析全都是我自己分析或者参考网上的,定有 ...
- Sencha Architect 安装与使用
http://www.sencha.com/products/touch/ Sencha SDK Tools Advanced JavaScript and CSS Project Build Too ...
- wp8 入门到精通 生命周期
- 在Salesforce中添加Workflow Rule
在Salesforce中可以添加Workflow Rule来执行特定的动作,比如说:当Object的某个字段发生变化时,根据变化的值去修改其他field,和Trigger的功能很类似,不过Trigge ...
- 以管理身份运行cmd
搜索出cmd程序,然后右键-以管理员身份运行
- Win7 Object_Header之TypeIndex解析
在暴力搜索内存进程对象反隐藏进程这篇文章中,我们提到: Object Header偏移0×008处Type成员为对象类型值,相同类型的对象具有相同的值. 自Window 7开始, _OBJECT_ ...
- 内核函数KiFastCallEntry
KiFastCallEntry() 机制分析 概述 Win32 子系统 API 调用 ntdll!ZwWriteFile() 函数 ntdll!KiFastSystemCall() 函数 _KUSER ...