【CodeForces - 746D】Green and Black Tea(思维)

题意:

两种茶各有一定数量,放在一行,同一种不能连续放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 ;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值