题意:
两种茶各有一定数量,放在一行,同一种不能连续放k个,问有没有合适的放置的方法。
思路:
最好就是间隔相等的放置,假设G比B多,一开始一个G一个B。一圈后,从头开始在每个G后面继续放G,直到没有G为止
ac代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<vector>
#include<unordered_map>
#define mod (1000000007)
using namespace std;
typedef long long ll;
const int maxn = 3e6 + 5;
const int inf = 0x3f3f3f3f;
char G='G',B='B';
int n,k,a,b;
int main() {
cin>>n>>k>>a>>b;
if(a<b) swap(a,b),swap(G,B);
int tt=ceil(1.0*a/(b+1));
if(k<tt) puts("NO");
else{
int md=a%(b+1),tmp;
tmp=md>0?1:0;
while(md--){
for(int i=0;i<tt;i++)putchar(G); a-=tt;
if(b) putchar(B),b--;
}
tt-=tmp;
while(a>0||b>0){
for(int i=0;i<tt;i++)putchar(G); a-=tt;
if(b) putchar(B),b--;
}
puts("");
}
return 0 ;
}