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 ...
随机推荐
- poj1904 二分图匹配+强连通分量
http://poj.org/problem?id=1904 Description Once upon a time there lived a king and he had N sons. An ...
- C# LINQ Unity 单例
C# LINQ 1. 自定义 Master,Kongfu 类 1 class Master 2 { 3 4 public int Id { get; set; } 5 public string ...
- Cleave js 使用
1111111111111111 xxxxxx Cleave.js 键入时格式化< input />内容 信用卡号码格式 明确 美国运通:从34/37开始 34 签证:从4开始 ...
- JavaScript学习14:表单处理
什么是表单? 在HTML中,表单是由<form>元素来表示的.而在JavaScript中,表单相应的则是HTMLFormElement类型.HTMLFormElement继承了HTMLEl ...
- HTML的高富帅
1,前端的内容(组成部分有以下三部分) HTML CSS JS 裸体的人 穿上好看的衣服 ...
- (MySQL里的数据)通过Sqoop Import HDFS 里 和 通过Sqoop Export HDFS 里的数据到(MySQL)(五)
下面我们结合 HDFS,介绍 Sqoop 从关系型数据库的导入和导出 一.MySQL里的数据通过Sqoop import HDFS 它的功能是将数据从关系型数据库导入 HDFS 中,其流程图如下所示. ...
- What's the difference between HEAD, working tree and index, in Git?
What's the difference between HEAD, working tree and index, in Git?
- YTU 2900: F-A Simple Question
2900: F-A Simple Question 时间限制: 1 Sec 内存限制: 128 MB 提交: 66 解决: 24 题目描述 今天,pasher打算在一个浪漫的花园和他的搭档们聚餐, ...
- iphone设备尺寸规格
1.以下是iphone各种设备的尺寸规格 2.开发时只需要按“逻辑分辨率”来,1x,2x,3x主要用于切图时按不同大小来切图,如1x的图就是按照“逻辑分辨率”大小的效果图切出来的原图,2x就是1x原图 ...
- win7下IIS7.0虚拟目录不存在的问题
问题:在IIS7.0下选中虚拟目录,右边浏览应用程序下,自动打开浏览器找开虚拟目录下的网站,但过一会什么都没有改变,再一次右边浏览应用程序,就提示 “虚拟目录不存在”. 解决方法:右键网站或下面的虚拟 ...