CodeForces - 1245 B - Restricted RPS(贪心)
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(贪心)的更多相关文章
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- 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 ...
- codeforces Codeforces Round #597 (Div. 2) B. Restricted RPS 暴力模拟
#include <bits/stdc++.h> using namespace std; typedef long long ll; ]; ]; int main() { int t; ...
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
- Codeforces Gym 100269E Energy Tycoon 贪心
题目链接:http://codeforces.com/gym/100269/attachments 题意: 有长度为n个格子,你有两种操作,1是放一个长度为1的东西上去,2是放一个长度为2的东西上去 ...
- CodeForces 797C Minimal string:贪心+模拟
题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...
- codeforces 803D Magazine Ad(二分+贪心)
Magazine Ad 题目链接:http://codeforces.com/contest/803/problem/D ——每天在线,欢迎留言谈论. 题目大意: 给你一个数字k,和一行字符 例: g ...
- Codeforces 980E The Number Games 贪心 倍增表
原文链接https://www.cnblogs.com/zhouzhendong/p/9074226.html 题目传送门 - Codeforces 980E 题意 $\rm Codeforces$ ...
随机推荐
- How to generate entities from database schema using doctrine-orm-module
1.安装好doctrine,在composer.json中添加如下 "require": { "php": "^5.6 || ^7.0", ...
- Linux Shell编程,双括号运算符(())
双括号运算符是shell非常强大的扩展. 这里简要介绍两种使用方式: 1.条件判断 跟在if.while.until,for等需要逻辑条件的命令后,进行逻辑判断 if(( expr));then … ...
- 我对KMP算法的理解
KMP算法的核心在于失配回溯表——pnext,相比于通过逐个比较来匹配字符串的朴素算法,KMP通过对模式串的分析,可以做到比较指针在主串上不回溯,一直向前. 1. KMP如何实现不回溯? 对于主串 t ...
- matplotlib TransformedPath和TransformedPatchPath
10:42:54 10:42:57 --Edit by yangray TransformedPath 继承于 TransformNode,支持对Path(曲线)执行非仿射变换并保存变换后的拷贝至缓存 ...
- Nginx知多少系列之(六)Linux下.NET Core项目负载均衡
目录 1.前言 2.安装 3.配置文件详解 4.工作原理 5.Linux下托管.NET Core项目 6.Linux下.NET Core项目负载均衡 7.负载均衡策略详解 8.Linux下.NET C ...
- 接口 ThreadMXBean 一个很好用的线程管理接口类 可以参考 jdk 帮助文档
概述 软件包 类 使用 树 已过时 索引 帮助 JavaTM Platform Standard Ed. 6 上一个类 下一个类 框架 无框架 所有类 摘要: 嵌套 ...
- C#多线程(4):进程同步Mutex类
Mutex 类 构造函数和方法 系统只能运行一个程序的实例 解释一下上面的示例 接替运行 进程同步示例 另外 Mutex 类 Mutex 中文为互斥,Mutex 类叫做互斥锁.它还可用于进程间同步的同 ...
- 一、uart&tty驱动
一.I.MX6 UART驱动 文件路径:\linux_IMX6_CoreC_3..35_for_Linux\drivers\tty\serial\imx.c .驱动入口函数:imx_serial_in ...
- **********Prometheus(三)******************
通过centos7.x来部署Prometheus ####同步时间,否则后面监控会有异常!!!!!####### 1. 创建文件夹,上传软件包.解压并将prometheus promtool两个命令复 ...
- 利用Ajax实现异步请求
Ajax 1.课程引入 静态网站和动态网站都是同步的,但同步方式有缺点:页面请求响应式阻塞,影响用户体验 为了解决这个问题,可以通过变通的手段实现页面的局部更新(隐藏帧),由于隐藏 ...