CF1659A
要连续的 $R$ 最少,即要尽量平分在 $B$ 的空隙里,
有 $b + 1$ 个位置可以填 $R$,
设 $x = \left\lfloor\dfrac{r}{b +1}\right\rfloor,y=r \% (b + 1)$,
显然让前 $y$ 个位置填 $x + 1$ 个,后 $y + 1 - r$ 个位置填 $x$ 个,
这样就达到了平分的效果了。
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 110;
int main() {
int T; scanf ("%d", &T);
while (T --) {
int n; scanf ("%d", &n);
int r, b; scanf ("%d%d", &r, &b);
int x = r / (b + 1), y = r % (b + 1); // 用 int 类型就不需要再 x = floor (r / (b + 1))
for (int i = 1; i <= y; ++i) {
for (int j = 1; j <= x + 1; ++j) cout << "R";
cout << "B";
}
for (int i = y + 1; i <= b; ++i) {
for (int j = 1; j <= x; ++j) cout << "R";
cout << "B";
}
for (int j = 1; j <= x; ++j) cout << "R"; // 因为最后以串 R 后面没有 B,单独取出来处理
cout << endl;
}
return 0;
}