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 ...
随机推荐
- HTML5学习之WebWork多线程处理(八)
多线程技术在服务端技术中已经发展的很成熟了,而在Web端的应用中却一直是鸡肋 在新的标准中,提供的新的WebWork API,让前端的异步工作变得异常简单. 使用:创建一个Worker对象,指向一个j ...
- Delphi字符串与字符数组之间的转换(初始化的重要性)
紧接着上篇博客讲解的内容: 将Char型数组转换为string类型还有下面的这种方法 但是我在测试的时候遇到了一些问题,并在下面进行了解释和总结 先说出我的总结 其实我们在学习编程的时候(比如我之前学 ...
- 【JAVA多线程概述】
一.多线程概述 一个进程中至少有一个线程,每一个线程都有自己运行的内容,这个内容可以称为线程要执行的任务. 不能没一个问题都使用多线程,能使用单线程解决的问题就不要使用多线程解决. 使用多线程的弊端: ...
- SQLAchemy Core学习之Reflection
如果以后万一有一个定义好了的库,可以用这种反射的方法,作常用的操作. #coding=utf-8 from datetime import datetime from sqlalchemy impor ...
- java中 this 和super的用法
通过用static来定义方法或成员,为我们编程提供了某种便利,从某种程度上可以说它类似于C语言中的全局函数和全局变量.但是,并不是说有了这种便利,你便可以随处使用,如果那样的话,你便需要认真考虑一下自 ...
- POJ 1163:The Triangle
Description 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a progr ...
- linux下java环境配置
非常简单的三行命令就搞定了! $ sudo add-apt-repository ppa:webupd8team/java$ sudo apt-get update$ sudo apt-get ins ...
- DSP using MATLAB 示例Example3.21
代码: % Discrete-time Signal x1(n) % Ts = 0.0002; n = -25:1:25; nTs = n*Ts; Fs = 1/Ts; x = exp(-1000*a ...
- react-redux(1)
基础 Array.prototype.reduce //类似的核心思想 const initState = ''; const actions = ['a', 'b', 'c']; const new ...
- CSS3-基于浮动的布局,响应式WEB设计,定位网页上的元素,设计打印页面的css技术
基于浮动的布局: 1.除非图片设置了宽度,否则始终应该要对浮动的图片设置一个宽度,这样可以让浏览器给其他内容腾出环绕的空间 2.当侧边栏的高度与主内容区的高度不一致的时候,可以用个margin进行调整 ...