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 ...
随机推荐
- MVC缓存03,扩展方法实现视图缓存
关于缓存,先前尝试了: ● 在"MVC缓存01,使用控制器缓存或数据层缓存"中,分别在控制器和Data Access Layer实现了缓存 ● 在"MVC缓存02,使用数 ...
- Mysql常用命令详解
Mysql安装目录 数据库目录 /var/lib/mysql/ 配置文件 /usr/share/mysql(mysql.server命令及配置文件) 相关命令 /usr/bin(mysqladmin ...
- UML- 模型图介绍
第一类 用例图 第二类 静态图 类图 对象图 包图第三类 行为图 状态图 活动图第四类 交互图 序列图 协助图第五类 实现图 构件图 部署图 1 用例图:从用户角度描述系统功能,以及每个系统功 ...
- Linux系统启动流程及安装命令行版本
Debian安装 之前也安装过很多次linux不同版本的系统,但安装后都是直接带有桌面开发环境的版本,直接可以使用,正好最近项目不是很忙,想一直了解下Linux的整个启动流程,以及如何从命令行模式系统 ...
- Hbuilder连接模拟器调试
Hbuilder是一个非常好用的HTML5开发IDE,我最喜欢的功能就是连接手机调试了,连接手机调试有两种途径,一是通过USB连接真机,二是下载安装一个安卓模拟器,让Hbuilder连接到安卓模拟器, ...
- mageView图片显示出来 ()
ImageView图片显示出来: igSign 是 ImageView的实例 igSign.setImageDrawable(getResources().getDrawable(R.drawable ...
- jbox使用总结
jbox是一个不错的插件 当使用get打开新页面的时候,可以使用h.对像ID来获得对像ID的值 Js代码 js代码: /** * @description: test * @author: BrinP ...
- 在Salesforce中编写Unit Test
Unit Test 也是一个 Class 文件,所以在创建 Unit Test 的时候要选择 Test Class 类型来创建,请看如下截图(在Eclipse中): 编写 Unit Test 基本流程 ...
- Codeforces Round #369 (Div. 2) D. Directed Roads dfs求某个联通块的在环上的点的数量
D. Directed Roads ZS the Coder and Chris the Baboon has explored Udayland for quite some time. The ...
- CmRegisterCallback使用方法
部分代码 #include "my_sys_fun.h"#ifdef __cplusplusextern "C"{#endif //驱动加载函数 NTSTATU ...