Codeforces Round #597 (Div. 2)

Let nn be a positive integer. Let a,b,ca,b,c be nonnegative integers such that a+b+c=na+b+c=n.

Alice and Bob are gonna play rock-paper-scissors nn times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock aa times, paper bb times, and scissors cc times.

Alice wins if she beats Bob in at least ⌈n2⌉⌈n2⌉ (n2n2 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,ca,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.

Input

The first line contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases.

Then, tt testcases follow, each consisting of three lines:

  • The first line contains a single integer nn (1≤n≤1001≤n≤100).
  • The second line contains three integers, a,b,ca,b,c (0≤a,b,c≤n0≤a,b,c≤n). It is guaranteed that a+b+c=na+b+c=n.
  • The third line contains a string ss of length nn. ss is made up of only 'R', 'P', and 'S'. The ii-th character is 'R' if for his ii-th Bob plays rock, 'P' if paper, and 'S' if scissors.

Output

For each testcase:

  • If Alice cannot win, print "NO" (without the quotes).
  • Otherwise, print "YES" (without the quotes). Also, print a string tt of length nn made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. tt must contain exactly aa 'R's, bb 'P's, and cc '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.

Example

Input

2
3
1 1 1
RPS
3
3 0 0
RPS

Output

YES
PSR
NO

Note

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≥⌈32⌉=23≥⌈32⌉=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<⌈32⌉=21<⌈32⌉=2.

水题,就是尽量赢,等不能赢了,剩下的看还能出什么,随便输出就行。

#include<bits/stdc++.h>
using namespace std;
char W[110000];
string s;
int main()
{
int t;
cin >> t;
while(t--)
{
int R, P, S,n;
cin >> n;
cin >> R >> P >> S;
cin >> s;
int sum = 0;
for (int i = 0;i < n;i++)
{
if (s[i] == 'R' && P > 0)
W[i] = 'P', P--;
else if (s[i] == 'P' && S > 0)
W[i] = 'S', S--;
else if (s[i] == 'S' && R > 0)
W[i] = 'R', R--;
else
W[i] = 'N', sum++;
}
if (sum > n/2)
{
puts("NO");
continue;
}
puts("YES");
for (int i = 0;i < n;i++)
{
if (W[i] == 'N')
{
if (R > 0)
{
cout << 'R';
R--;
}
else if (P > 0)
{
cout << 'P';
P--;
}
else if (S > 0)
{
cout << 'S';
S--;
}
}
else
cout << W[i];
}
puts(""); } return 0;
}

CodeForces - 1245 B - Restricted RPS(贪心)的更多相关文章

  1. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  2. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  3. Codeforces Round #597 (Div. 2) B. Restricted RPS

    链接: https://codeforces.com/contest/1245/problem/B 题意: Let n be a positive integer. Let a,b,c be nonn ...

  4. codeforces Codeforces Round #597 (Div. 2) B. Restricted RPS 暴力模拟

    #include <bits/stdc++.h> using namespace std; typedef long long ll; ]; ]; int main() { int t; ...

  5. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  6. Codeforces Gym 100269E Energy Tycoon 贪心

    题目链接:http://codeforces.com/gym/100269/attachments 题意: 有长度为n个格子,你有两种操作,1是放一个长度为1的东西上去,2是放一个长度为2的东西上去 ...

  7. CodeForces 797C Minimal string:贪心+模拟

    题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...

  8. codeforces 803D Magazine Ad(二分+贪心)

    Magazine Ad 题目链接:http://codeforces.com/contest/803/problem/D ——每天在线,欢迎留言谈论. 题目大意: 给你一个数字k,和一行字符 例: g ...

  9. Codeforces 980E The Number Games 贪心 倍增表

    原文链接https://www.cnblogs.com/zhouzhendong/p/9074226.html 题目传送门 - Codeforces 980E 题意 $\rm Codeforces$ ...

随机推荐

  1. VSCode设置大小写转换的快捷键

    本文已同步到专业技术网站 www.sufaith.com, 该网站专注于前后端开发技术与经验分享, 包含Web开发.Nodejs.Python.Linux.IT资讯等板块. VSCode在默认情况下没 ...

  2. alg-最长不重复子串

    class Solution { public: int lengthOfLongestSubstring(const std::string& s) { int max_length = 0 ...

  3. Python 中如何查看进行反汇编

    dis模块       Python 反汇编是通过 dis 这个模块来查看的,一般有两种方式可以用来查看     方式一: 在命令行中使用 dis 查看   >>> def test ...

  4. not found 什么时候触发

    eq: BEGIN        DECLARE EXIT HANDLER FOR NOT FOUND SET o_state = 999;         select count(1) into ...

  5. IO流学习总结

    IO: 概述: IO流用来处理设备之间的数据传输,如上传文件和下载文件 Java对数据的操作是通过流的方式 Java用于操作流的对象都在IO包中按照数据流向: 输入流 读入数据 从操作系统上读入文件到 ...

  6. 06-移动web之flex布局

    一.基本概念 flex布局又叫伸缩布局 .弹性布局 .伸缩盒布局 .弹性盒布局 Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性. ...

  7. 知识点一:OSI模型初识

    OSI(开放系统)模型是一组协议的集合,它使得两个不同的系统之间能够互相通信,分为七层 第一层:物理层 物理层负责把逐个的比特(01)从一个节点移动到下个节点 具体体现在如何把比特转换成电或者光信号. ...

  8. L14梯度消失、梯度爆炸

    梯度消失.梯度爆炸以及Kaggle房价预测 梯度消失和梯度爆炸 考虑到环境因素的其他问题 Kaggle房价预测 梯度消失和梯度爆炸 深度模型有关数值稳定性的典型问题是消失(vanishing)和爆炸( ...

  9. Connections in Galaxy War ZOJ - 3261 (并查集)

    点权并查集的反向离线操作 题目大意:有n个stars,每一个都一定的“颜值”.然后stars与stars之间可以相连,query c表示再与c相连的stars中,颜值比c高的,stars的标号,如果有 ...

  10. WEBMIN(CVE-2019-15107) 学习

    简单介绍: Webmin是目前功能最强大的基于Web的Unix系统管理工具.管理员通过浏览器访问Webmin的各种管理功能并完成相应的管理动作.目前Webmin支持绝大多数的Unix系统,这些系统除了 ...