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 nonnegative integers such that a+b+c=n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈n2⌉ (n2 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,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.
思路:
贪心算一下。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
char res[110];
string s;
int main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--)
{
int a, b, c;
cin >> n;
cin >> a >> b >> c;
cin >> s;
int sum = 0;
for (int i = 0;i < n;i++)
{
if (s[i] == 'R' && b > 0)
res[i] = 'P', b--;
else if (s[i] == 'P' && c > 0)
res[i] = 'S', c--;
else if (s[i] == 'S' && a > 0)
res[i] = 'R', a--;
else
res[i] = 'N', sum++;
}
if (sum > n/2)
{
cout << "NO" << endl;
continue;
}
cout << "YES" << endl;
for (int i = 0;i < n;i++)
{
if (res[i] == 'N')
{
if (a > 0)
{
cout << 'R';
a--;
}
else if (b > 0)
{
cout << 'P';
b--;
}
else if (c > 0)
{
cout << 'S';
c--;
}
}
else
cout << res[i];
}
cout << endl;
}
return 0;
}
Codeforces Round #597 (Div. 2) B. Restricted RPS的更多相关文章
- 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 Round #597 (Div. 2)
A - Good ol' Numbers Coloring 题意:有无穷个格子,给定 \(a,b\) ,按以下规则染色: \(0\) 号格子白色:当 \(i\) 为正整数, \(i\) 号格子当 \( ...
- Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid
链接: https://codeforces.com/contest/1245/problem/D 题意: Shichikuji is the new resident deity of the So ...
- Codeforces Round #597 (Div. 2) C. Constanze's Machine
链接: https://codeforces.com/contest/1245/problem/C 题意: Constanze is the smartest girl in her village ...
- Codeforces Round #597 (Div. 2) A. Good ol' Numbers Coloring
链接: https://codeforces.com/contest/1245/problem/A 题意: Consider the set of all nonnegative integers: ...
- Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid 题解 最小生成树
题目链接:https://codeforces.com/contest/1245/problem/D 题目大意: 平面上有n座城市,第i座城市的坐标是 \(x[i], y[i]\) , 你现在要给n城 ...
- 计算a^b==a+b在(l,r)的对数Codeforces Round #597 (Div. 2)
题:https://codeforces.com/contest/1245/problem/F 分析:转化为:求区间内满足a&b==0的对数(解释见代码) ///求满足a&b==0在区 ...
- Codeforces Round #597 (Div. 2) F. Daniel and Spring Cleaning 数位dp
F. Daniel and Spring Cleaning While doing some spring cleaning, Daniel found an old calculator that ...
- Codeforces Round #597 (Div. 2) E. Hyakugoku and Ladders 概率dp
E. Hyakugoku and Ladders Hyakugoku has just retired from being the resident deity of the South Black ...
随机推荐
- java8 time包的简单使用
import com.sun.org.apache.xml.internal.res.XMLErrorResources_tr; import java.text.DateFormat; import ...
- C 语言函数手册:涵盖字符测试、字符串操作、内存管理、时间换算、数学计算、文件操作、进程管理、文件权限控制、信号处理、接口处理、环境变量、终端控制
1. 字符测试函数 函数 说明 isascii() 判断字符是否为ASCII码字符 2. 字符串操作 函数 说明 gcvt() 将浮点型数转换为字符串(四舍五入) index() 查找字符串并返回首次 ...
- python 之 subprocesss 模块、configparser 模块
6.18 subprocesss 模块 常用dos命令: cd : changedirectory 切换目录 tasklist:查看任务列表 tasklist | findstr python ...
- 计算机网络自顶向下方法第4章 网络层:数据平面 (Network layer)
4.1 网络层概述 网络层主要功能为转发(将数据从路由器输入接口转移到合适的输出接口)和路由选择(端到端的路径选择),每台路由器都有一张转发表,用最长前缀匹配规则来转发. 4.1.1 转发和路由选择 ...
- Scala Actor入门
介绍 Scala的Actor类似于Java中的多线程编程.但是不同的是,Scala的Actor提供的模型与多线程有所不同.Scala的Actor尽可能地避免锁和共享状态,从而避免多线程并发时出现资源争 ...
- SAS学习笔记50 SAS数据集索引
在没有索引的情况下,SAS是一条接一条的扫描观测:有索引时,直接跳到该索引对应的观测所在位置.总结一句话就是:节省时间,节省内存,提高效率 当然并不是任何情况下使用索引都能提高工作效率,因为建立索引本 ...
- JQuery EasyUI框架
1. JQuery EasyUI框架概述 1.1. JQuery EasyUI是什么东西 答:JQuery EasyUI就是一套基础JQuery的富客户端的UI框架.像这些将常用的控件封装成一个UI ...
- UnknownError: session deleted because of page crash from tab crashed
一.问题 在docker上跑Selenium+ChromeDriver+Chrome无头模式报错: UnknownError: unknown error: session deleted becau ...
- 简单添加自己的驱动程序到Linux内核树中
背景: 移植4g模块的时候,看到文档中有添加驱动到内核的步骤,于是趁着这个机会,展开有关的学习. 了解更多可以访问:<Kconfig语法简介> Target :hi3531d Linux ...
- flume-ng version出现错误Error: Could not find or load main class org.apache.flume.tools.GetJavaPrope的解决办法
错误: 找不到或无法加载主类 org.apache.flume.tools.GetJavaProperty或者Error: Could not find or load main class org. ...