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 ...
随机推荐
- [Xamarin] - "GenerateJavaStubs" 异常之解决
背景 新建的 Xamarin 项目,编译失败. Error The "GenerateJavaStubs" task failed unexpectedly.Error The s ...
- 二进制知识(java中的位操作)
文章目录 前言 机器数 真值 原码 反码 补码 计算机中保存的都是补码 位操作 强制转换,精度丢失 前言 讲二进制的东西,必须要说明是多少位机器,八位机上的 1000 1000 和 十六位机上的 10 ...
- 作业练习P194,jieba应用,读取,分词,存储,生成词云,排序,保存
import jieba #第一题 txt='Python是最有意思的编程语言' words=jieba.lcut(txt) #精确分词 words_all=jieba.lcut(txt,cut_al ...
- matplotlib实例笔记
下面的图型是在一幅画布上建立的四个球员相关数据的极坐标图 关于这个图的代码如下: #_*_coding:utf-8_*_ import numpy as np import matplotlib.py ...
- react实现提示消息容器,可以动态添加,删除内部子提示消息
import React, { useState, useRef, useEffect } from 'react' import PropTypes from 'prop-types' import ...
- Java8新特性 - 方法引用与构造器引用
方法引用 若Lambda体中的内容有方法已经实现了,我们可以使用"方法应用",可以理解为方法引用是Lambda表达式的另外一种表现形式. 使用操作符"::"将方 ...
- App客户端性能测试点总结
一.内存 测试范围1. 空闲状态下的应用内存消耗情况2. 中等规格状态下的应用内存消耗情况3. 满规格状态下的应用内存消耗情况4. 应用内存峰值情况5. 应用内存泄露情况6. 应用是否常驻内存7. 压 ...
- .ajaxStart() / .ajaxStop() —— ajax请求开始时 / 结束时触发
一..ajaxStart()——ajax请求开始时触发 描述:ajax请求开始时触发 .ajaxStart()的回调函数,全局的,所有的ajax都可以用 写法:元素.ajaxStart(functi ...
- Python之原始数据-1
一.数据对于模型来说是基础,是数据成就了模型,而现在的又是一个数据时代,比如:淘宝等.通过对用户数据的分析挖掘,预测用户的消费习惯等,再比如:人工智能.通过提取摄像头的图片帧数,通过分析图片,得出具体 ...
- SQL 多并发 多人取号,防止重复取号SQL 办法
BEGIN TRAN SELECT * from 表明 WITH(HOLDLOCK) UPDATE 表名 SET 值=1 WHERE 字段=@carrierNo; ...