链接:

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的更多相关文章

  1. codeforces Codeforces Round #597 (Div. 2) B. Restricted RPS 暴力模拟

    #include <bits/stdc++.h> using namespace std; typedef long long ll; ]; ]; int main() { int t; ...

  2. Codeforces Round #597 (Div. 2)

    A - Good ol' Numbers Coloring 题意:有无穷个格子,给定 \(a,b\) ,按以下规则染色: \(0\) 号格子白色:当 \(i\) 为正整数, \(i\) 号格子当 \( ...

  3. 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 ...

  4. Codeforces Round #597 (Div. 2) C. Constanze's Machine

    链接: https://codeforces.com/contest/1245/problem/C 题意: Constanze is the smartest girl in her village ...

  5. Codeforces Round #597 (Div. 2) A. Good ol' Numbers Coloring

    链接: https://codeforces.com/contest/1245/problem/A 题意: Consider the set of all nonnegative integers: ...

  6. Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid 题解 最小生成树

    题目链接:https://codeforces.com/contest/1245/problem/D 题目大意: 平面上有n座城市,第i座城市的坐标是 \(x[i], y[i]\) , 你现在要给n城 ...

  7. 计算a^b==a+b在(l,r)的对数Codeforces Round #597 (Div. 2)

    题:https://codeforces.com/contest/1245/problem/F 分析:转化为:求区间内满足a&b==0的对数(解释见代码) ///求满足a&b==0在区 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. [转帖]Hadoop与Spark比较

    Hadoop与Spark比较 https://www.cnblogs.com/charlesblc/p/6206198.html 感觉自己落下好多东西没有学习 先看这篇文章:http://www.hu ...

  2. input的小技巧 清除自动记录

    input 消除自动记忆功能 在html里就可以直接清除了<input type="text" autocomplete="off"> input ...

  3. PAT(B) 1037 在霍格沃茨找零钱(Java)

    题目链接:1037 在霍格沃茨找零钱 (20 point(s)) 题目描述 如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 -- 就如海格告诉哈利的:"十七个银西可(Sickle) ...

  4. Codeforces Round #576 (Div. 1) 简要题解 (CDEF)

    1198 C Matching vs Independent Set 大意: 给定$3n$个点的无向图, 求构造$n$条边的匹配, 或$n$个点的独立集. 假设已经构造出$x$条边的匹配, 那么剩余$ ...

  5. C#使用管理员权限打开cmd执行命令行

    最近遇到个棘手的问题,服务器远程连不上,但是ftp可以,可能远程连接的服务挂了或者防火墙入站规则有点问题,想要重启,得找机房工作人员,还是挺麻烦的 想了想可以上传个执行cmd命令的东西,然后远程访问触 ...

  6. Spark机器学习基础-监督学习

    监督学习 0.线性回归(加L1.L2正则化) from __future__ import print_function from pyspark.ml.regression import Linea ...

  7. git 讲解

    部署结构: - Git版本控制 - Git的使用 - 快速控制服务器代码版本 - 有利于团队协作 - 安装流程 现有代码 -> 编辑区 -> 寄存区 -> 版本库 1. 安装GIT ...

  8. J.U.C之读写锁:ReentrantReadWriteLock

    此篇博客所有源码均来自JDK 1.8 重入锁ReentrantLock是排他锁,排他锁在同一时刻仅有一个线程可以进行访问,但是在大多数场景下,大部分时间都是提供读服务,而写服务占有的时间较少.然而读服 ...

  9. 安装HANA Rules Framework(HRF)

    1. 收集文档 1.1  SAP HANA Rules Framework by the SAP HANA Academy link 1.2  HANA Rules Framework (HRF) b ...

  10. 时间都去哪儿了?开源一个统计iPhone上App运行时间和打开次数的小工具【iOS8已失效】

    如今,大家每天都有大量时间花在手机上,但是,大家有没有想过自己的时间都花在哪些App上了呢?相信很多人都有这样的需求,不过iOS系统本身并不能显示每个App的运行时间和次数,因此,本人写了这样一个小工 ...