Codeforces Round #782 (Div. 2) A. Red Versus Blue

A. Red Versus Blue(构造题)

time limit per test

1 second

memory limit per test

256 megabytes

Team Red and Team Blue competed in a competitive FPS. Their match was streamed around the world. They played a series of n matches.

In the end, it turned out Team Red won r times and Team Blue won b times. Team Blue was less skilled than Team Red, so b was strictly less than r.

You missed the stream since you overslept, but you think that the match must have been neck and neck since so many people watched it. So you imagine a string of length n where the i − t h i-th ith character denotes who won the i − t h i-th ith match — it is R if Team Red won or B if Team Blue won. You imagine the string was such that the maximum number of times a team won in a row was as small as possible. For example, in the series of matches RBBRRRB, Team Red won 3 times in a row, which is the maximum.

You must find a string satisfying the above conditions. If there are multiple answers, print any.

Input

The first line contains a single integer t ( 1 ≤ t ≤ 1000 ) (1 \le t \le 1000) (1t1000) — the number of test cases.

Each test case has a single line containing three integers n n n, r r r, and b b b ( 3 ≤ n ≤ 100 ; 1 ≤ b < r ≤ n , r + b = n ) (3 \leq n \leq 100; 1 \leq b < r \leq n, r+b=n) (3n100;1b<rn,r+b=n).

Output

For each test case, output a single line containing a string satisfying the given conditions. If there are multiple answers, print any.

Examples

input

Copy

3
7 4 3
6 5 1
19 13 6

output

Copy

RBRBRBR
RRRBRR
RRBRRBRRBRRBRRBRRBR

input

Copy

6
3 2 1
10 6 4
11 6 5
10 9 1
10 8 2
11 9 2

output

Copy

RBR
RRBRBRBRBR
RBRBRBRBRBR
RRRRRBRRRR
RRRBRRRBRR
RRRBRRRBRRR

Note

The first test case of the first example gives the optimal answer for the example in the statement. The maximum number of times a team wins in a row in RBRBRBR is 1. We cannot minimize it any further.

The answer for the second test case of the second example is RRBRBRBRBR. The maximum number of times a team wins in a row is 2, given by RR at the beginning. We cannot minimize the answer any further.

A题不错,很好的的锻炼思维。

最少的最大连胜次数就让他平均分配,因为B一定比R小,所以一定是B作为隔板分割R,分多少块取决于B的数量,数量就是B数量多一,直接R除 B + 1 B+1 B+1可以得到分的块数t,而每块的R的数量就是 t x = R / t tx=R/t tx=R/t,但是由于除法是向下取整,所以会有R遗漏,遗漏的数量小于 t x tx tx,让 R % t R\%t R%t就能得到有 l a s t last last块R需要放多一个R。

因此,R的块数 t t t,每块R的数量 t x tx tx,B的数量 b b b,R块多放一个的数量 l a s t last last 都有了,就循环放就好了。

#include <iostream>
#include <cstring>
using namespace std;
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    while (n--) {
        string a = "";
        int x, r, b;
        cin >> x >> r >> b;
        int t = r / (b + 1);
        int tx = r / t;
        int last = r % (b + 1);
        // cout << last << endl;
        while (x > 0) {//x表示总长度
            int tmp = t;
            while (tmp-- && x > 0) {
                a += 'R';
                x--;
            }
            if (last) {
                a += 'R';
                x--;
                last--;//把R放完之后,就判断是不是还要一个R
            }
            if (b > 0) {
                a += 'B';
                x--;
            }
            b--;
        }
        cout << a << endl;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值