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$ ...
随机推荐
- 使用ping命令探测系统
什么是ping命令 ping命令是测试网络连接.信息发送和接收状况的实用型工具,是系统内置的探测性工具.它的原理是:每台网络上的主机都有唯一确定的IP地址,用户给目标IP发送一个数据报,对方就要返回一 ...
- MTK Android 源码目录分析
Android 源码目录分析 Android 4.0 |-- abi (application binary interface:应用二进制接口)|-- art (average retrieval ...
- Java第六天,API中常用的类,StringBuffer、StringBuilder、包装类、System类的使用
System (1)这个类中有很多可以获取系统信息的类. public class SystemLearn { public static void main(String[] args) { lon ...
- Python爬虫系列(二):requests基础
1.发送请求: import requests # 获取数据#r是一个 response 对象.包含请求返回的内容r = requests.get('https://github.com/timeli ...
- hadoop(七)集群配置同步(hadoop完全分布式四)|9
前置配置:rsync远程同步|xsync集群分发(hadoop完全分布式准备三)|9 1. 分布式集群分配原则 部署分配原则 说明Namenode和secondarynamenode占用内存较大,建议 ...
- 深入了解CI/CD:工具、方法、环境、基础架构的全面指南
本文来自Rancher Labs 持续集成和持续交付(CI/CD)是DevOps背后的助推力之一.如果你的企业正在考虑使用DevOps,那么CI/CD绝对是需要考虑的其中一部分.但是CI/CD到底意味 ...
- git撤销已经push到远端的commit
在使用git时,push到远端后发现commit了多余的文件,或者希望能够回退到以前的版本. 先在本地回退到相应的版本: git reset --hard <版本号> // 注意使用 -- ...
- Win10安装Keras+Tensorflow+Opencv
Win10安装keras 安装 Anaconda 清华加速下载链接: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 我选择的版本是: A ...
- webWMS开发过程记录(四)- 整体设计
分层 View(Servlet/Action/JSP)--> Service(接口/实现类) --> Dao(接口/实现类) 所用技术 Struts2 Hibernate Spring J ...
- Python基础:按位异或 ^ ,按位或 | ,按位与 &
前言文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取http: ...