CF1245B.Restricted RPS
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let n be a positive integer. Let a,b,c be nonnegative integers such that a+b+c=n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈2n⌉ (2n rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
- rock beats scissors;
- paper beats rock;
- scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a,b,c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
设 n 为一个正整数,a,b,c 为非负整数,满足 a+b+c=n。
Alice 和 Bob 将进行 n 轮“石头剪刀布”游戏。Alice 已知 Bob 每一轮将出的手势序列,但她必须恰好出 a 次石头、b 次布、c 次剪刀。
若 Alice 在至少 ⌈2n⌉(即 2n 向上取整)轮中击败 Bob,则 Alice 获胜;否则 Alice 失败。
注意,在“石头剪刀布”中:
- 石头击败剪刀;
- 布击败石头;
- 剪刀击败布。
任务是:给定 Bob 的手势序列以及数字 a,b,c,判断 Alice 是否能够获胜;若可以获胜,则输出任意一种 Alice 可采用的获胜手势序列。
若存在多种可行答案,输出任意一种即可。
输入格式
The first line contains a single integer t (1≤t≤100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
- The first line contains a single integer n (1≤n≤100).
- The second line contains three integers, a,b,c (0≤a,b,c≤n). It is guaranteed that a+b+c=n.
- The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
第一行包含一个整数 t(1≤t≤100)—— 表示测试用例的数量。
接下来是 t 个测试用例,每个测试用例包含三行:
- 第一行包含一个整数 n(1≤n≤100)。
- 第二行包含三个整数 a,b,c(0≤a,b,c≤n)。保证 a+b+c=n。
- 第三行包含一个长度为 n 的字符串 s。s 仅由字符 'R'、'P' 和 'S' 组成。其中第 i 个字符为 'R' 表示 Bob 在第 i 轮出剪刀(Rock),为 'P' 表示出布(Paper),为 'S' 表示出石头(Scissors)。
输出格式
For each testcase:
- If Alice cannot win, print "NO" (without the quotes).
- Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
- If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
对于每个测试用例:
- 如果 Alice 无法获胜,则输出
"NO"(不带引号)。 - 否则,输出
"YES"(不带引号),并输出一个长度为 n 的字符串 t,该字符串仅由字符'R'、'P'和'S'组成——即 Alice 可用于获胜的手势序列。字符串 t 必须恰好包含 a 个'R'、b 个'P'和 c 个'S'。 - 若存在多个合法答案,输出任意一个即可。
输出中的 "YES" / "NO" 部分不区分大小写(即 "yEs"、"no" 或 "YEs" 均为有效答案)。注意:字符 'R'、'P' 和 'S' 区分大小写。
输入输出样例
输入#1
2 3 1 1 1 RPS 3 3 0 0 RPS
输出#1
YES PSR NO
说明/提示
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3≥⌈23⌉=2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1<⌈23⌉=2.
在第一个测试用例中,第一回合,Alice 出布,Bob 出石头,因此 Alice 战胜 Bob;第二回合,Alice 出剪刀,Bob 出布,因此 Alice 战胜 Bob;第三回合,Alice 出石头,Bob 出剪刀,因此 Alice 战胜 Bob。Alice 共战胜 Bob 3 次,且 3≥⌈23⌉=2,故 Alice 获胜。
在第二个测试用例中,Alice 唯一可出的手势序列为 "RRR"。Alice 仅在最后一回合战胜 Bob,因此 Alice 无法获胜。1<⌈23⌉=2。
输入解题思路,AI测评打分。不知道怎么写?