代码如下:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
char str[10000600];
int main()
{
int n,k,a,b;
char aa,bb;
int flag;
while(~scanf("%d%d%d%d",&n,&k,&a,&b))
{
aa='G'; bb='B'; //a cun xiao
if(a>b)
{
swap(a,b);
swap(aa,bb);
}
for(int i=0;i<n;i++)
str[i]=bb;
flag=0;
for(int i=k;i<n;i+=k+1)
{
if(a>0)
{
str[i]=aa;
a--;
}
else
{
flag=1;
}
}
if(!flag)
{
for(int i=0;i<n;i++)
{
if(a==0)
break;
if(str[i]==aa || (i>0 && str[i-1]==aa) || (i+1<n && str[i+1]==aa))
continue;
str[i]=aa;
a--;
}
for(int i=0;i<n;i++)
printf("%c",str[i]);
printf("\n");
}
else
printf("NO\n");
}
return 0;
}