思路:先放多的,多的都是以k个连成一块,然后少的往里插。
#include<bits/stdc++.h>
using namespace std;
char str[100005];
int main()
{int n,k,a,b,flag;cin>>n>>k>>a>>b;char aa,bb;aa='G';bb='B';if(a>b){swap(a,b);aa='B';bb='G';}for(int i=1;i<=n;i++){str[i]=bb;}flag=1;for(int i=k+1;i<=n;i+=k+1){if(a<=0){flag=0;break;}str[i]=aa;a--;}if(flag){for(int i=1;i<=n;i++){if(!a) break;if(str[i]==aa||str[i-1]==aa||str[i+1]==aa) continue;str[i]=aa;a--;}for(int i=1;i<=n;i++)cout<<str[i];cout<<endl;}elsecout<<"NO"<<endl;return 0;
}