【21.58%】【codeforces 746D】Green and Black Tea
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.
Innokentiy doesn’t like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.
Input
The first line contains four integers n, k, a and b (1 ≤ k ≤ n ≤ 105, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that a + b = n.
Output
If it is impossible to drink n cups of tea, print “NO” (without quotes).
Otherwise, print the string of the length n, which consists of characters ‘G’ and ‘B’. If some character equals ‘G’, then the corresponding cup of tea should be green. If some character equals ‘B’, then the corresponding cup of tea should be black.
If there are multiple answers, print any of them.
Examples
input
5 1 3 2
output
GBGBG
input
7 2 2 5
output
BBGBGBB
input
4 3 4 0
output
NO
【题目链接】:http://codeforces.com/contest/746/problem/D
【题解】
最后必然是分成a/k 个绿茶块,b/k个黑茶块;
如果a/k==b/k
显然可以交替出现;
如果a/k>b/k
则先放k个a,然后放一个b;
这样a-=k,b-=1;
则a/k会越来越逼近b/k;
最后交替出现就可以了。
balabala
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
//const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
int n,k,a,b;
char t[2];
string ans = "";
int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);rei(k);rei(a);rei(b);
t[0]='G',t[1] = 'B';
if (a < b)
swap(a,b),swap(t[0],t[1]);
bool ok = false;
while ( (a/k)>(b/k))
{
if (a<k || b<1)
break;
rep1(i,1,k)
ans+=t[0];
ans+=t[1];
a-=k;
b--;
}
while (a>0 && b>0)
{
int ma = min(a,k);
rep1(i,1,ma)
ans+=t[0];
a-=ma;
ma = min(b,k);
rep1(i,1,ma)
ans+=t[1];
b-=ma;
}
if (a>k)
{
puts("NO");
return 0;
}
rep1(i,1,a)
ans+=t[0];
if (b>k)
{
puts("NO");
return 0;
}
rep1(i,1,b)
ans+=t[1];
cout << ans << endl;
return 0;
}
【21.58%】【codeforces 746D】Green and Black Tea的更多相关文章
- Codeforces 746D:Green and Black Tea(乱搞)
http://codeforces.com/contest/746/problem/D 题意:有n杯茶,a杯绿茶,b杯红茶,问怎么摆放才可以让不超过k杯茶连续摆放,如果不能就输出NO. 思路:首先,设 ...
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【21.37%】【codeforces 579D】"Or" Game
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【21.21%】【codeforces round 382D】Taxes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【58.33%】【codeforces 747B】Mammoth's Genome Decoding
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 757D】Felicity's Big Secret Revealed
[题目链接]:http://codeforces.com/problemset/problem/757/D [题意] 给你一个01串; 让你分割这个01串; 要求2切..n+1切; 对于每一种切法 所 ...
- 【codeforces 757E】Bash Plays with Functions
[题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...
- 【77.78%】【codeforces 625C】K-special Tables
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【30.23%】【codeforces 552C】Vanya and Scales
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- 剑指offer 1-6
1. 二维数组中的查找 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 分析 ...
- PyCharm2019 永久激活
<!-- 2019激活码 2019-06-21新更新 --> D00F1BDTGF-eyJsaWNlbnNlSWQiOiJEMDBGMUJEVEdGIiwibGljZW5zZWVOYW1l ...
- DAY1-作业
Python-day1-------> 本节内容: Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据 ...
- struts1之工作原理
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/zkn_CS_DN_2013/article/details/34452341 1.初始化:strut ...
- jmeter的关联-正则表达式的应用
LoadRunnner中的关联为web_reg_save_param,查找左右边界,下次请求的时候会用到上次请求服务器返回的数据,那么我们把符合左右边界的数据保存下来,以便下次请求的时候用到. jme ...
- oracle控制何时触发审计动作
1)By session / By Access by session对每个session中发生的重复操作只记录一次 by access对每个session中发生的每次操作都记录,而不管是否重复. 对 ...
- Person Re-identification 系列论文笔记(八):SPReID
Human Semantic Parsing for Person Re-identification Kalayeh M M, Basaran E, Gokmen M, et al. Human S ...
- 洛谷P2607 骑士
题目描述 Z国的骑士团是一个很有势力的组织,帮会中汇聚了来自各地的精英.他们劫富济贫,惩恶扬善,受到社会各界的赞扬. 最近发生了一件可怕的事情,邪恶的Y国发动了一场针对Z国的侵略战争.战火绵延五百里, ...
- Maven启用代理访问
如果你的公司正在建立一个防火墙,并使用HTTP代理服务器来阻止用户直接连接到互联网.如果您使用代理,Maven将无法下载任何依赖. 为了使它工作,你必须声明在 Maven 的配置文件中设置代理服务器: ...
- oracle函数 TO_DATE(X[,c2[,c3]])
[功能]将字符串X转化为日期型 [参数]c2,c3,字符型,参照to_char() [返回]字符串 如果x格式为日期型(date)格式时,则相同表达:date x 如果x格式为日期时间型(timest ...