zoukankan      html  css  js  c++  java
  • CodeForces

    Codeforces Round #597 (Div. 2)

    Let nn be a positive integer. Let a,b,ca,b,c be nonnegative integers such that a+b+c=na+b+c=n.

    Alice and Bob are gonna play rock-paper-scissors nn times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock aa times, paper bb times, and scissors cc times.

    Alice wins if she beats Bob in at least ⌈n2⌉⌈n2⌉ (n2n2 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,ca,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.

    Input

    The first line contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases.

    Then, tt testcases follow, each consisting of three lines:

    • The first line contains a single integer nn (1≤n≤1001≤n≤100).
    • The second line contains three integers, a,b,ca,b,c (0≤a,b,c≤n0≤a,b,c≤n). It is guaranteed that a+b+c=na+b+c=n.
    • The third line contains a string ss of length nn. ss is made up of only 'R', 'P', and 'S'. The ii-th character is 'R' if for his ii-th Bob plays rock, 'P' if paper, and 'S' if scissors.

    Output

    For each testcase:

    • If Alice cannot win, print "NO" (without the quotes).
    • Otherwise, print "YES" (without the quotes). Also, print a string tt of length nn made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. tt must contain exactly aa 'R's, bb 'P's, and cc 'S's.
    • If there are multiple answers, print any of them.

    The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.

    Example

    Input

    2
    3
    1 1 1
    RPS
    3
    3 0 0
    RPS
    

    Output

    YES
    PSR
    NO
    

    Note

    In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3≥⌈32⌉=23≥⌈32⌉=2, so Alice wins.

    In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1<⌈32⌉=21<⌈32⌉=2.

    水题,就是尽量赢,等不能赢了,剩下的看还能出什么,随便输出就行。

    #include<bits/stdc++.h>
    using namespace std;
    char W[110000];
    string s;
    int main()
    {
        int t;
        cin >> t;
        while(t--)
        {
            int R, P, S,n;
            cin >> n;
            cin >> R >> P >> S;
            cin >> s;
            int sum = 0;
            for (int i = 0;i < n;i++)
            {
                if (s[i] == 'R' && P > 0)
                    W[i] = 'P', P--;
                else if (s[i] == 'P' && S > 0)
                    W[i] = 'S', S--;
                else if (s[i] == 'S' && R > 0)
                    W[i] = 'R', R--;
                else
                    W[i] = 'N', sum++;
            }
            if (sum > n/2)
            {
                puts("NO");
                continue;
            }
             puts("YES");
            for (int i = 0;i < n;i++)
            {
                if (W[i] == 'N')
                {
                    if (R > 0)
                    {
                        cout << 'R';
                        R--;
                    }
                    else if (P > 0)
                    {
                        cout << 'P';
                        P--;
                    }
                    else if (S > 0)
                    {
                        cout << 'S';
                        S--;
                    }
                }
                else
                    cout << W[i];
            }
           puts("");
    
        }
    
        return 0;
    }
  • 相关阅读:
    1379. Find a Corresponding Node of a Binary Tree in a Clone of That Tree
    1389. Create Target Array in the Given Order
    1385. Find the Distance Value Between Two Arrays
    1382. Balance a Binary Search Tree
    PHP的 __DIR__ 作用【转】
    PHP:Allowed memory size of 134217728 bytes exhausted问题解决方法【转】
    PHP: POST Content-Length of xxx bytes exceeds the limit of 8388608 bytes【转】
    PhpStorm 如何快速查找文件【转】
    .gitkeep的作用【转】
    php copy 函数使用 【转】
  • 原文地址:https://www.cnblogs.com/lunatic-talent/p/12798613.html
Copyright © 2011-2022 走看看