Cf #782 (Div. 2)

A. Red Versus Blue

题意

共有 n 个连续字符 ,其中有 a 个  R ,b 个 B (a+b=n),问怎么排列使 R 的最大连续个数最小,输出一种可能排列

思路

b 个B可以把a个R分成 b+1 份,每份放   a%(b+1) 个,余下的从前往后依次放一个

代码

 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int a, b, n;
        cin >> n >> a >> b;
        string s;
        int x = b + 1;
        while (a > b)
        {
            s += 'R';
            a -= x;
        }
        for (int i = 1; i <= a; i++)
            cout << "R" << s << "B";
        for (int i = a + 1; i <= b; i++)
            cout << s << "B";
        cout << s << endl;
    }
    return 0;
}

 

posted @ 2022-04-19 18:56  黎_lyh  阅读(39)  评论(0)    收藏  举报