D. Green and black tea time limit/test 1 second memory limit per test 256 megabytes input standard input output Standa RD output
Innokentiy likes tea is very much more and today he wants to drink exactly n cups. He would is happy to drink the but he had exactly n tea bags, a of them are green and B are black.
Innokentiy doesn ' t like to drink's same tea (green or black) is more than k times in a row. Your task is to determine "order of brewing tea bags so" innokentiy'll be able to drink n cups of tea, without Dr Inking 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 "I" contains four integers n, K, A and B (1≤k≤n≤105, 0≤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 T Ea. It is guaranteed that a + b = N. Output
If it is impossible to drink n cups the 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 to be green. If some character equals ' B ', then the corresponding cup of tea should is black.
If There are multiple answers, print any of them. Examples Input
5 1 3 2
Output
Gbgbg
Input
7 2 2 5
Output
Bbgbgbb
Input
4 3 4 0
Output
NO
The question: have n pack of tea, a pack of green tea, B pack black tea, each kind of tea at most continuously drink k, ask to be able to drink the solution of N Pack tea, if there is no output no.
Idea: Drink a lot first, try to drink, until ab equal or drank K Cup, if AB equal that do not have to tube k, take turns drink OK, if a is not equal to B, that originally many or many, first will another kind of tea drink a cup, and then drink another.
Make two kinds of tea tend to be equal, equal can solve, if appear to drink a kind of tea but tea has been drunk, output No.
#include <bits/stdc++.h> using namespace std;
#define LL Long int #define MAXN 100010 Char S[MAXN];
int main () {int n, K, A, B, p = 0, I;
scanf ("%d%d%d", &n, &k, &a, &b);
BOOL flag = 1, c;
if (a>b) {int tmp = min (k, a-b);
for (i = 1;i <= tmp;i++) {a--;
s[p++] = ' G ';
} c = 0;
}else if (b>a) {int tmp = min (k, b-a);
for (i = 1;i <= tmp;i++) {b--;
s[p++] = ' B ';
} c = 1; }else {for (i = 1;i <= a*2;i++) s[p++] = ((i%2==1)? '
G ': ' B ');
A = b = 0; } while (a| | b) {if (a==b) {if (c) for (i = 1;i <= a*2;i++) s[p++] = ((i%2==1)? '
G ': ' B '); else for (i = 1;i <= a*2;i++) s[p++] = ((i%2==1)? '
B ': ' G ');
Break
} if (c) {//for (i = 1;i <= min (k, a-b); i++) {if (a==0) {flag = 0;
Break } a--;
s[p++] = ' G ';//printf ("%d%d%d\n", C, K, b-a);
int tmp = min (k, b-a);
for (i = 1;i <= tmp;i++) {b--;
s[p++] = ' B ';
}//} c = 1;
}else {//printf ("%d\n", c);
if (b==0) {flag = 0;
Break
}//for (i = 1;i <= min (k, b-a); i++) {b--;
s[p++] = ' B ';
int tmp = min (k, a-b);
for (i = 1;i <= tmp;i++) {a--;
s[p++] = ' G ';
} c = 0;
} if (!flag) printf ("no\n");
else {S[p] = ' I ';
printf ("%s\n", s); }
}