codeforce 386(div2) D. Green and Black Tea

来源:互联网 发布:股市交易软件 编辑:程序博客网 时间:2024/06/03 04:05

Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.

Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.

Input

The first line contains four integers nka and b (1 ≤ k ≤ n ≤ 1050 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed thata + b = n.

Output

If it is impossible to drink n cups of tea, print "NO" (without quotes).

Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.

If there are multiple answers, print any of them.

这边比如a==0或b==0是比较容易判断的。(两个不能同时为零,因为n>=1)

a==b就是间隔的输出。

这边假设a>b,(与a<b的情况是一样的),拿最优的情况就是a平均分成b+1份,如果有余数的话就是某几项要加1,判断是否会超过k

然后就是模拟了;


AC代码:

#include<stdio.h>#include<iostream>#include<vector>#include<queue>#include<algorithm>using namespace std;typedef long long int ll;int main() {int i, j, k, a, b, n;//a--G, b--Bscanf("%d%d%d%d", &n, &k, &a, &b);//for (i = 1; i <= n; i++)if (a == 0) {if (k >= b) {for (i = 1; i <= b; i++) {printf("B");}}else {printf("NO");}}else if (b == 0) {if (k >= a) {for (i = 1; i <= a; i++) {printf("G");}}else {printf("NO");}}else {if (a == b) {for (i = 1; i <= a; i++) {printf("GB");}}else if (a > b) {int mod = a%(b+1), t=a/(b+1);if (mod == 0) {if (t <= k) {for (i = 1; i <= b + 1; i++) {if (i != b + 1) {for (j = 1; j <= t; j++) {printf("G");}printf("B");}else {for (j = 1; j <= t; j++) {printf("G");}}}}else {printf("NO");}}else {if (t + 1 > k) {printf("NO");return 0;}for (i = 1; i <= mod; i++) {for (j = 1; j <= t + 1; j++) {printf("G");}printf("B");}for (i = mod + 1; i <= b + 1; i++) {if (i != b + 1) {for (j = 1; j <= t; j++) {printf("G");}printf("B");}else {for (j = 1; j <= t; j++) {printf("G");}}}}}else {int mod = b % (a + 1), t = b / (a + 1);if (mod == 0) {if (t <= k) {for (i = 1; i <= a + 1; i++) {if (i != a + 1) {for (j = 1; j <= t; j++) {printf("B");}printf("G");}else {for (j = 1; j <= t; j++) {printf("B");}}}}else {printf("NO");}}else {if (t + 1 > k) {printf("NO");return 0;}for (i = 1; i <= mod; i++) {for (j = 1; j <= t + 1; j++) {printf("B");}printf("G");}for (i = mod + 1; i <= a + 1; i++) {if (i != a + 1) {for (j = 1; j <= t; j++) {printf("B");}printf("G");}else {for (j = 1; j <= t; j++) {printf("B");}}}}}}return 0;}


0 0
原创粉丝点击