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$ ...
随机推荐
- Loop Unrolling 循环展开
在csapp第五章5.2中提到了循环展开(loop unrolling).这里展开一下为什么循环展开可以提升程序的效率. 以书中计算数组和的两段代码为例: 1.未展开: void psum1(floa ...
- istream_iterator && istream_iteratorbuf
注意 读字符时, std::istream_iterator 默认跳过空白符(除非用 std::noskipws 或等价物禁用,而 std::istreambuf_iterator 不跳过.另外, s ...
- python3(一)
print('test', '怎么自动建了这么多目录', 'aaaaaaa') #test 怎么自动建了这么多目录 aaaaaaa 注释# # ---------------------------- ...
- Powershell操作MySQL
最近再用Python写一些监控脚本,并将监控数据输出到MySQL中,最后通过Python抓取MySQL中的数据进行监控汇总告警 考虑到一些微软产品使用Powershell更为方便,于是找了些资料,尝试 ...
- MYSQ创建联合索引,字段的先后顺序,对查询的影响分析
MYSQ创建联合索引,字段的先后顺序,对查询的影响分析 前言 最左匹配原则 为什么会有最左前缀呢? 联合索引的存储结构 联合索引字段的先后顺序 b+树可以存储的数据条数 总结 参考 MYSQ创建联合索 ...
- Spring3.2 中 Bean 定义之基于 XML 配置方式的源码解析
Spring3.2 中 Bean 定义之基于 XML 配置方式的源码解析 本文简要介绍了基于 Spring 的 web project 的启动流程,详细分析了 Spring 框架将开发人员基于 XML ...
- 最近遇到adb connection 问题,总结一下
最近eclipse总是遇到adb connection问题,网上搜索了一些解决方法,在cmd tool工具下adb kill-server ,adb start-server ,甚至重启都无效.然后我 ...
- 11-JS变量
一. JavaScript 是什么 JavaScript是一种运行在客户端(浏览器)的脚本语言 客户端:客户端是相对于服务器而言的,在这里先简单理解为浏览器 浏览器就是一个客户端软件,浏览器从服务器上 ...
- shell脚本知识
1.提示符变量PS1 修改提示符变量:PS1="[u\@\h \t \w]" 修改环境变量设置文件bash_profile需要使用source或者.加上该文件使之生效 位置参数从1 ...
- niuke --abc
链接:https://ac.nowcoder.com/acm/contest/1083/A来源:牛客网 给出一个字符串s,你需要做的是统计s中子串”abc”的个数.子串的定义就是存在任意下标a< ...