CF173A.Rock-Paper-Scissors
普及-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Nikephoros and Polycarpus play rock-paper-scissors. The loser gets pinched (not too severely!).
Let us remind you the rules of this game. Rock-paper-scissors is played by two players. In each round the players choose one of three items independently from each other. They show the items with their hands: a rock, scissors or paper. The winner is determined by the following rules: the rock beats the scissors, the scissors beat the paper and the paper beats the rock. If the players choose the same item, the round finishes with a draw.
Nikephoros and Polycarpus have played n rounds. In each round the winner gave the loser a friendly pinch and the loser ended up with a fresh and new red spot on his body. If the round finished in a draw, the players did nothing and just played on.
Nikephoros turned out to have worked out the following strategy: before the game began, he chose some sequence of items A = (_a_1, _a_2, ..., a__m), and then he cyclically showed the items from this sequence, starting from the first one. Cyclically means that Nikephoros shows signs in the following order: _a_1, _a_2, ..., a__m, _a_1, _a_2, ..., a__m, _a_1, ... and so on. Polycarpus had a similar strategy, only he had his own sequence of items B = (_b_1, _b_2, ..., b__k).
Determine the number of red spots on both players after they've played n rounds of the game. You can consider that when the game began, the boys had no red spots on them.
尼基福罗斯和波利卡尔普斯玩“石头剪刀布”游戏。输的一方会被轻轻捏一下(不会太疼)!
我们来回顾一下这个游戏的规则:石头剪刀布由两名玩家进行。每一轮中,双方各自独立地选择三种手势之一:石头、剪刀或布,并用手势表示出来。胜负判定规则如下:石头胜剪刀,剪刀胜布,布胜石头;若双方出相同的手势,则该轮为平局。
尼基福罗斯和波利卡尔普斯共进行了 $ n $ 轮游戏。每一轮中,获胜者会友好地捏一下失败者,失败者身上因此出现一个崭新的红色小点;若该轮为平局,则双方什么也不做,直接进入下一轮。
尼基福罗斯事先制定了一套策略:游戏开始前,他选定一个长度为 $ m $ 的手势序列 $ A = (a_1, a_2, \dots, a_m) $,然后按循环方式依次展示该序列中的手势,即从第一个手势开始,依次展示 $ a_1, a_2, \dots, a_m $,接着再次从 $ a_1 $ 开始,如此反复:$ a_1, a_2, \dots, a_m, a_1, a_2, \dots, a_m, a_1, \dots $。波利卡尔普斯也采用类似策略,但他有自己的手势序列 $ B = (b_1, b_2, \dots, b_k) $。
请计算在进行完 $ n $ 轮游戏后,两名玩家身上各自有多少个红色小点。初始时,两人身上均无红点。
输入格式
The first line contains integer n (1 ≤ n ≤ 2·109) — the number of the game's rounds.
The second line contains sequence A as a string of m characters and the third line contains sequence B as a string of k characters (1 ≤ m, k ≤ 1000). The given lines only contain characters "R", "S" and "P". Character "R" stands for the rock, character "S" represents the scissors and "P" represents the paper.
第一行包含一个整数 n(1 ≤ n ≤ 2⋅109)—— 表示游戏的轮数。
第二行包含字符串形式的序列 A,长度为 m;第三行包含字符串形式的序列 B,长度为 k(1 ≤ m, k ≤ 1000)。所给字符串仅包含字符 "R"、"S" 和 "P"。其中,"R" 表示石头(Rock),"S" 表示剪刀(Scissors),"P" 表示布(Paper)。
输出格式
Print two space-separated integers: the numbers of red spots Nikephoros and Polycarpus have.
输出两个用空格分隔的整数:尼基福罗斯和波利卡普斯各自拥有的红色斑点数量。
输入输出样例
输入#1
7 RPS RSPP
输出#1
3 2
输入#2
5 RRRRRRRR R
输出#2
0 0
说明/提示
In the first sample the game went like this:
- R - R. Draw.
- P - S. Nikephoros loses.
- S - P. Polycarpus loses.
- R - P. Nikephoros loses.
- P - R. Polycarpus loses.
- S - S. Draw.
- R - P. Nikephoros loses.
Thus, in total Nikephoros has 3 losses (and 3 red spots), and Polycarpus only has 2.
在第一个样例中,游戏过程如下:
- R - R:平局。
- P - S:尼基福罗斯输。
- S - P:波利卡普斯输。
- R - P:尼基福罗斯输。
- P - R:波利卡普斯输。
- S - S:平局。
- R - P:尼基福罗斯输。
因此,尼基福罗斯总共输了 3 次(对应 3 个红点),而波利卡普斯仅输了 2 次。
输入解题思路,AI测评打分。不知道怎么写?