http://codeforces.com/contest/746/problem/D

首先说下一定是NO的情况。

假设a > b

那么,b最多能把a分成b + 1分,如果每份刚好是k的话,那么就最多能支持a的最大值是(b + 1) * k

其实就好比如,分成3分的话,x1 + x2  + x3 = m,每个xi <= k的,那么最多就是3 * k了。

所以判定下后,

后面的,如果a多,就用a,(注意不能超过k个)

b多,用b。一路模拟。

因为已经保证有解了,所以模拟后就是答案。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
void pr(int k, char ch) {
for (int i = ; i <= k; ++i) {
printf("%c", ch);
}
}
void work() {
int n, k, a, b;
scanf("%d%d%d%d", &n, &k, &a, &b);
if ((LL)k * (min(a, b) + ) < max(a, b)) {
cout << "NO" << endl;
return;
}
int to = ;
int has = ;
if (a > b) {
while (to < n) {
if (a > b && has < k) {
printf("G");
has++;
a--;
to++;
} else {
printf("B");
b--;
has = ;
to++;
}
}
} else {
while (to < n) {
if (b > a && has < k) {
printf("B");
has++;
to++;
b--;
} else {
printf("G");
has = ;
to++;
a--;
}
}
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

D. Green and Black Tea 贪心 + 构造的更多相关文章

  1. 贪心/构造/DP 杂题选做Ⅲ

    颓!颓!颓!(bushi 前传: 贪心/构造/DP 杂题选做 贪心/构造/DP 杂题选做Ⅱ 51. CF758E Broken Tree 讲个笑话,这道题是 11.3 模拟赛的 T2,模拟赛里那道题的 ...

  2. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...

  3. 【21.58%】【codeforces 746D】Green and Black Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 贪心/构造/DP 杂题选做

    本博客将会收录一些贪心/构造的我认为较有价值的题目,这样可以有效的避免日后碰到 P7115 或者 P7915 这样的题就束手无策进而垫底的情况/dk 某些题目虽然跟贪心关系不大,但是在 CF 上有个 ...

  5. 贪心/构造/DP 杂题选做Ⅱ

    由于换了台电脑,而我的贪心 & 构造能力依然很拉跨,所以决定再开一个坑( 前传: 贪心/构造/DP 杂题选做 u1s1 我预感还有Ⅲ(欸,这不是我在多项式Ⅱ中说过的原话吗) 24. P5912 ...

  6. Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)

    A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  7. Codeforces 1082D Maximum Diameter Graph (贪心构造)

    <题目链接> 题目大意:给你一些点的最大度数,让你构造一张图,使得该图的直径最长,输出对应直径以及所有的边. 解题分析:一道比较暴力的构造题,首先,我们贪心的想,要使图的直径最长,肯定是尽 ...

  8. hdu 4982 贪心构造序列

    http://acm.hdu.edu.cn/showproblem.php?pid=4982 给定n和k,求一个包含k个不相同正整数的集合,要求元素之和为n,并且其中k-1的元素的和为完全平方数 枚举 ...

  9. Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造

    题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...

随机推荐

  1. lightoj 1138 - Trailing Zeroes (III)【二分】

    题目链接:http://lightoj.com/volume_showproblem.php? problem=1138 题意:问 N. 末尾 0 的个数为 Q 个的数是什么? 解法:二分枚举N,由于 ...

  2. 运算符与类型转换 mogondb简介

    运算符与类型转换   1.运算符 (1)分类 算术运算符.关系运算符.逻辑运算符.位运算符.赋值运算符.其他运算符 >.算术运算符: 运算符 描述 + 把两个操作数相加 - 从第一个操作数中减去 ...

  3. quick-cocos2d-x教程10:实现血条效果。

    血条是常见功能.能够通过一个血条背景和一个不断改变的血条宽度.来实现少血. 在MainScence.lua中,先改代码: function MainScene:ctor()     local bg ...

  4. 数据库建表参考(SQL Server)

      (1).字段设置为Not Null+Default Value.原因:减少三值判断,可为Null的字段要多判断null:另外,定长字段为null也占空间,变长字段为空字符串也是不占空间,所以设置成 ...

  5. [LeetCode]Two Sum 【Vector全局指针的使用】

    无序数组返回两个元素和为给定值的下标. tricks:无序.返回下标增序.返回的是原始数组的下标. vector<int>*pa; bool cmp(int x,int y){ retur ...

  6. Java数据类型的分类

    java支持的类型分为两类:基本类型和引用类型 一.基本类型 4类8种: (1)整型:int.short.long.byte. (2)浮点型:float.double. (3)字符型:char. (4 ...

  7. vs2010中设置qt环境的智能识别方案

    Qt搭建请参考:Win7系统VS2010下搭建qt开发环境 搭建好之后,虽然可以编译过去,但是写代码时,编辑器无法识别,也没有智能提示,并且代码中都是红色的提示如下: 此时需要设置一下include路 ...

  8. beego5---gosqlite安装

    WindowsWindows下的安装也非常简单,只要到 SQLite3 的下载页面,下载 Windows 下的预编译包 DLL 的压缩包(sqlite-dll-win32-x86-XXX.zip),然 ...

  9. Oracle - 数据更新 - 事务

    /* 事务 事务是为了控制数据异步访问所使用的一种技术 就类似于java中的锁机制 synchronized,只不过功能更加强大 事务不能进行嵌套,当我们开启一个事务的之后作的每一次dml语句都属于这 ...

  10. 关于页面上输入框中 空格 、0 、NULL 的处理 示例

    ep.setPositionNum(get("positionNum").toString()); ep.setClasstype(get("classtype" ...