链接:

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. LeetCode 242. 有效的字母异位词(Valid Anagram)

    242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...

  2. K8S从入门到放弃系列-(13)Kubernetes集群mertics-server部署

    集群部署好后,如果我们想知道集群中每个节点及节点上的pod资源使用情况,命令行下可以直接使用kubectl top node/pod来查看资源使用情况,默认此命令不能正常使用,需要我们部署对应api资 ...

  3. Go语言学习笔记(9)——接口类型

    接口 Go 语言提供了另外一种数据类型即接口,它把所有的具有共性的方法定义在一起,任何其他类型只要实现了这些方法就是实现了这个接口. /* 定义接口 */ type interface_name in ...

  4. Arm-Linux 移植 FFMPEG库 + x264

      背景: ffmpeg 中带有264的解码,没有编码,需要添加x264.libx264是一个自由的H.264编码库,是x264项目的一部分,使用广泛,ffmpeg的H.264实现就是用的libx26 ...

  5. error: snap "eclipse" has "install-snap" change in progress

    在Ubuntu 18.04使用snap安装eclipse软件报时错: inuxidc@linuxidc:~$ snap install --classic eclipse error: snap &q ...

  6. Bipartite Checking CodeForces - 813F (线段树按时间分治)

    大意: 动态添边, 询问是否是二分图. 算是个线段树按时间分治入门题, 并查集维护每个点到根的奇偶性即可. #include <iostream> #include <sstream ...

  7. Spring Cloud Alibaba学习笔记(5) - 整合Sentinel及Sentinel规则

    整合Sentinel 应用整合Sentinel 在dependencies中添加依赖,即可整合Sentinel <dependency> <groupId>com.alibab ...

  8. Linux文件属性整理

    Linux系统是一种典型的多用户系统,不同的用户处于不同的地位,拥有不同的权限.为了保护系统的安全性,Linux系统对不同的用户访问同一文件(包括目录文件)的权限做了不同的规定.在Linux中我们可以 ...

  9. windows下安装phpredis扩展

    根据phpyinfo获取自己的php信息 x86,php5.6,TS,VC11 在pecl网站上找到对应的版本 5.6 Thread Safe (TS) x86 https://pecl.php.ne ...

  10. SQL根据指定节点ID获取所有父级节点和子级节点(转载)

    --根据指定节点ID获取所有子节点-- WITH TEMP AS ( ' --表的主键ID UNION ALL SELECT T0.* FROM TEMP,table_name T0 WHERE TE ...