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;
}

原文地址:https://www.cnblogs.com/YDDDD/p/11797726.html

时间: 2024-11-05 22:01:48

Codeforces Round #597 (Div. 2) B. Restricted RPS的相关文章

Codeforces Round #597 (Div. 2) A. Good ol&#39; Numbers Coloring

链接: https://codeforces.com/contest/1245/problem/A 题意: Consider the set of all nonnegative integers: 0,1,2,-. Given two integers a and b (1≤a,b≤104). We paint all the numbers in increasing number first we paint 0, then we paint 1, then 2 and so on. Ea

题解Codeforces Round #597 (Div. 2)

A:送分,裸的gcd. 1 #include<stdio.h> 2 #define il inline 3 #define it register int 4 int T,a,b,d; 5 il void gcd(int a,int b){ 6 if(!b){d=a;return;} 7 gcd(b,a%b); 8 } 9 il void fr(int &num){ 10 num=0;char c=getchar();int p=1; 11 while(c<'0'||c>'

Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid

题意: 二维平面上n个点,每个点可以建厂,也可以与其他点连边,建厂花费为\(c_i\),与j连边花费为\((k_i+k_j)*dis(i,j)\),dis为两点之间的欧式距离,求让每个点都通电的最小花费与方案 思路: 维护使这个点通电的花费的优先队列,一开始先把建厂放进去,然后每次拿出最小花费的点i,再用i去更新与i建路的花费(有点像最小生成树). #include<bits/stdc++.h> #define ll long long #define pii pair<int,int&

codeforces Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid

#include<bits/stdc++.h> using namespace std ; int n; struct City { int id; long long x,y; //坐标 long long cc,kk; //自建的花费,连线的花费 bool self;//是否建站 int fa;//连线的站 bool operator < (const City & a)const { return cc<a.cc; } } c[2005]; int main() {

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 Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she w

Codeforces Round #597 (Div. 2)D(最小生成树)

/*每个点自己建立一座发电站相当于向超级源点连一条长度为c[i]的边,连电线即为(k[i]+k[j])*两点间曼哈顿距离,跑最小生成树(prim适用于稠密图,kruscal适用于稀疏图)*/ #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int fa[2007];int x[2007],y[2007];int c[2007],k[2007];long long m[2007][2007];vecto

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我