D. Green and Black Tea 贪心 + 构造
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 贪心 + 构造的更多相关文章
- 贪心/构造/DP 杂题选做Ⅲ
颓!颓!颓!(bushi 前传: 贪心/构造/DP 杂题选做 贪心/构造/DP 杂题选做Ⅱ 51. CF758E Broken Tree 讲个笑话,这道题是 11.3 模拟赛的 T2,模拟赛里那道题的 ...
- 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation
题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...
- 【21.58%】【codeforces 746D】Green and Black Tea
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 贪心/构造/DP 杂题选做
本博客将会收录一些贪心/构造的我认为较有价值的题目,这样可以有效的避免日后碰到 P7115 或者 P7915 这样的题就束手无策进而垫底的情况/dk 某些题目虽然跟贪心关系不大,但是在 CF 上有个 ...
- 贪心/构造/DP 杂题选做Ⅱ
由于换了台电脑,而我的贪心 & 构造能力依然很拉跨,所以决定再开一个坑( 前传: 贪心/构造/DP 杂题选做 u1s1 我预感还有Ⅲ(欸,这不是我在多项式Ⅱ中说过的原话吗) 24. P5912 ...
- 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 ...
- Codeforces 1082D Maximum Diameter Graph (贪心构造)
<题目链接> 题目大意:给你一些点的最大度数,让你构造一张图,使得该图的直径最长,输出对应直径以及所有的边. 解题分析:一道比较暴力的构造题,首先,我们贪心的想,要使图的直径最长,肯定是尽 ...
- hdu 4982 贪心构造序列
http://acm.hdu.edu.cn/showproblem.php?pid=4982 给定n和k,求一个包含k个不相同正整数的集合,要求元素之和为n,并且其中k-1的元素的和为完全平方数 枚举 ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造
题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...
随机推荐
- Please enter a commit message to explain why this merge is necessary.
Please enter a commit message to explain why this merge is necessary. 请输入提交消息来解释为什么这种合并是必要的 git 在pul ...
- Object.getOwnPropertyNames()
1.Object.getOwnPropertyNames(),遍历实例属性(包括不可枚举),返回属性名组成的数组 var arr = ["a", "b", &q ...
- 我的家乡:三河古镇已经登上央视CCTV-1新闻联播啦!
在烟雨朦胧时走在古镇的青石街上,别有一番风味!第一幅图为央视的直播车,第二副图为漂亮的三河夜景色!
- 2016/05/25 get和post的区别
get是从服务器上获取数据,post是向服务器传送数据. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到.post是通过HTTP ...
- Spring Security调研记录【七】--核心模型与实现
网上有非常多关于Spring Security文章中,都觉得Spring Security(相对于shiro)过于复杂,个人觉得复杂的是Spring Security的官方文档而不是Spring Se ...
- YTU 2556: 空洞
2556: 空洞 时间限制: 1 Sec 内存限制: 128 MB 提交: 24 解决: 17 题目描述 春天来了,单身的霞姐越发地空虚寂寞,于是她想到一个办法,她认 为只要把英文字母上的洞都涂满 ...
- zabbix 监控ssdb
zabbix 的啥基础知识啥的,请看由本站大牛凉白开先生写的zabbix教程.这里说说如何监控ssdb.SSDB 是一个 C/C++ 语言开发的高性能 NoSQL 数据库, 支持 KV, list, ...
- bzoj3544
set+贪心 感觉当div2C挺好的... set维护前缀和%m,当前答案为sum[r]-sum[l-1],我们当然希望sum[l-1]是sum[r]的后继或者最小的数,所以求出来比较一下就行了 #i ...
- Bootstrap 面板
基本的面板:<div class="panel panel-default"> <div class="panel-body"> 这是一 ...
- get与post提交方式区别?
1.get <!--表单数据作为HTTP GET请求发送给action 规定的URL,并将数据附加在URL之后,由客户端直接发送给服务器.表单数据不能太长,也不能含有非ASCII码的字符--&g ...