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

  1. 2
  2. 3
  3. 1 1 1
  4. RPS
  5. 3
  6. 3 0 0
  7. RPS

Output

  1. YES
  2. PSR
  3. 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.

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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. char W[110000];
  4. string s;
  5. int main()
  6. {
  7. int t;
  8. cin >> t;
  9. while(t--)
  10. {
  11. int R, P, S,n;
  12. cin >> n;
  13. cin >> R >> P >> S;
  14. cin >> s;
  15. int sum = 0;
  16. for (int i = 0;i < n;i++)
  17. {
  18. if (s[i] == 'R' && P > 0)
  19. W[i] = 'P', P--;
  20. else if (s[i] == 'P' && S > 0)
  21. W[i] = 'S', S--;
  22. else if (s[i] == 'S' && R > 0)
  23. W[i] = 'R', R--;
  24. else
  25. W[i] = 'N', sum++;
  26. }
  27. if (sum > n/2)
  28. {
  29. puts("NO");
  30. continue;
  31. }
  32. puts("YES");
  33. for (int i = 0;i < n;i++)
  34. {
  35. if (W[i] == 'N')
  36. {
  37. if (R > 0)
  38. {
  39. cout << 'R';
  40. R--;
  41. }
  42. else if (P > 0)
  43. {
  44. cout << 'P';
  45. P--;
  46. }
  47. else if (S > 0)
  48. {
  49. cout << 'S';
  50. S--;
  51. }
  52. }
  53. else
  54. cout << W[i];
  55. }
  56. puts("");
  57. }
  58. return 0;
  59. }

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. 【Selenium03篇】python+selenium实现Web自动化:元素三类等待,多窗口切换,警告框处理,下拉框选择

    一.前言 最近问我自动化的人确实有点多,个人突发奇想:想从0开始讲解python+selenium实现Web自动化测试,请关注博客持续更新! 这是python+selenium实现Web自动化第三篇博 ...

  2. Codeup 25594 Problem H 例题5-8 Fibonacci数列

    题目描述 输入一个正整数n,求Fibonacci数列的第n个数.Fibonacci数列的特点:第1,2个数为1,1.从第3个数开始,概述是前面两个数之和.即: 1,1,2,3,5,8,13,21 - ...

  3. 第一天 简单的python认证登陆代码

    #!/usr/bin/env python3# -*- coding:utf-8 -*-# name:zzyu welcome = '''-----------welcome to home----- ...

  4. mysql 使用技巧 分页limit

    mysql 分页使用 limit关键字,limit x,y (x代表从哪条数据开始,y代表页面大小.mysql第一条数据在limit计算时索引为0) 前10条 limit , 从第1条开始的10条 l ...

  5. AJ学IOS 之第一次打开Xcode_git配置,git简单学习

    AJ分享,必须精品 一:错误 当第一次打开Xcode我们进行commit操作的时候会报错: The working copy “测试” failed to commit files. * Please ...

  6. Thinking in Java,Fourth Edition(Java 编程思想,第四版)学习笔记(六)之Initialization & Cleanup

    Two of these safety issues are initialization and cleanup. initialization -> bug cleanup -> ru ...

  7. How Many Answers Are Wrong HDU - 3038 (经典带权并查集)

    题目大意:有一个区间,长度为n,然后跟着m个子区间,每个字区间的格式为x,y,z表示[x,y]的和为z.如果当前区间和与前面的区间和发生冲突,当前区间和会被判错,问:有多少个区间和会被判错. 题解:x ...

  8. B - Red and Black 直接BFS+队列

    There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A ...

  9. mapstruct使用详解

    我们都知道,随着一个工程的越来越成熟,模块划分会越来越细,其中实体类一般存于 domain 之中,但 domain 工程最好不要被其他工程依赖,所以其他工程想获取实体类数据时就需要在各自工程写 mod ...

  10. PHP代码审计理解(一)----Metinfo5.0变量覆盖

    0x01 漏洞简介 这个漏洞是metinfo5.0变量覆盖漏洞,并且需要结合文件包含.我使用的cms版本是5.3,事实上已经修复了这个漏洞(5.0的cms源码已经找不到了哈),但是我们可以借他来学习理 ...