• Green and Black Tea time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Innokentiy likes tea very much and to


D. Green and Black Tea

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard 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 ntea 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 thata + 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

思路：模拟

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int n,k,a,b,i,j,l,m;
while(scanf("%d%d%d%d",&n,&k,&a,&b)!=EOF)
{
if(a==b)
{
for(i=1;i<=n;i+=2)
{
printf("GB");
}
printf("\n");
}
else if(a>b)
{
int num=a/(b+1);
int res=a%(b+1);
if(num>k||(num==k&&res!=0))
{
printf("NO\n");
}
else
{
m=n;
for(i=1;i<=res;i++)
{
for(j=1;j<=num+1;j++)
{
printf("G");
}
printf("B");
}
for(i=1;i<=b-res;i++)
{
for(j=1;j<=num;j++)
{
printf("G");
}
printf("B");
}
for(i=1;i<=num;i++)
{
printf("G");
}
printf("\n");
}
}
else if(a<b)
{
swap(a,b);
int num=a/(b+1);
int res=a%(b+1);
if(num>k||(num==k&&res!=0))
{
printf("NO\n");
}
else
{
m=n;
for(i=1;i<=res;i++)
{
for(j=1;j<=num+1;j++)
{
printf("B");
}
printf("G");
}
for(i=1;i<=b-res;i++)
{
for(j=1;j<=num;j++)
{
printf("B");
}
printf("G");
}
for(i=1;i<=num;i++)
{
printf("B");
}
printf("\n");
}
}
}
return 0;
}


展开全文
• Green and Black Tea time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Innokentiy likes tea very much and to


D. Green and Black Tea

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard 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
题意：就是给定G和B共有n个，其中G有a个，B有b个，让你确定一种序列是的连着的B不超过k个，同理连着的G也不能超过K个。
思路：构造，构造。把数量少的字母插入到数量较多的字符串里面。刚开始我们就每隔k个插入一个字母，最后如果还有剩余的，我们就一个一个的插入就好了，具体的思路看代码
#include <iostream>
#include <cstdio>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <cstring>

using namespace std;

const int max_n = 100005;
int n,k,a,b;
char s[max_n];

int main() {
cin >> n >> k >> a >> b;
char B='B',G='G';
if(a > b){//确定a一顶小于b，把a插入到b里面就可以了
swap(a,b);
swap(G,B);
}
for(int i = 0; i< n;i++){/初始化原始序列
s[i] = B;
}
for(int i = k;i < n;i+=k+1){//每隔k个插入一个a，如果发现a完之后b剩余的还比K多输出NO.
if(a == 0){
printf("NO\n");
return 0;
}
s[i] = G;
a--;
}
for(int i = 0;i < n&& a>0 ;i++){//间隔插入a
if(s[i] == G||(i > 0&&s[i-1] == G)||((i+1)<n&&s[i+1]==G)){
continue;
}
s[i] = G;
a--;
}
cout << s;
return 0;
}



展开全文
• 一款小型的java编译工具:BlackTea-java <br>一、软件介绍： 在你学习java的时候对频繁使用cmd感到麻烦吗？对eclipse等大型工具感到占内存太大的话？您可以使用本程序，它不到200k,它间接的使用了JDK方便了大家...
• Green and Black Tea time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Innokentiy likes tea very much and today


Green and Black Tea

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard 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

题意：有n杯茶，分G，B两种，分别有a，b杯。 要求在连续喝一种茶不能超过k次。输出喝茶的顺序

题解：构造一下就好了，代码写的好挫啊 Σ( ° △ °|||)︴

代码如下：

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e5+10;
char str[maxn];
int main()
{
int n,k,a,b;
while(scanf("%d%d%d%d",&n,&k,&a,&b)!=EOF)
{
if(a>=b)
{
int cnt=a/k;//a被分成几块
double num=a*1.0/k;
if(num==cnt)
cnt--;
if(cnt==0)
cnt=1;
int count=cnt;
cnt=b/count;//b每一块最少要填几个
if(cnt>k)
cnt=k;
if(cnt==0)
cnt=1;
int temp=0;
while(a>0&&b>0)
{
cnt=a/k;
num=a*1.0/k;
if(num==cnt)
cnt--;
if(cnt==0)
cnt=1;
count=cnt;
cnt=b/count;//每次都要更新cnt
if(cnt>k)
cnt=k;
if(cnt==0)
cnt=1;
if(a>=k)
{
for(int i=0;i<k;++i)
str[temp++]='G';
a-=k;
}
else
{
for(int i=0;i<a;++i)
str[temp++]='G';
a-=a;
}
if(a==0)
cnt=k;
if(b>=cnt)
{
for(int i=0;i<cnt;++i)
str[temp++]='B';
b-=cnt;
}
else
{
for(int i=0;i<b;++i)
str[temp++]='B';
b-=b;
}
}
if(a>=k)
{
for(int i=0;i<k;++i)
str[temp++]='G';
a-=k;
}
else
{
for(int i=0;i<a;++i)
str[temp++]='G';
a-=a;
}
if(a!=0 || b!=0)
printf("NO\n");
else{
str[temp]='\0';
printf("%s\n",str);
}
}
else
{
int cnt=b/k;
double num=b*1.0/k;
if(num==cnt)
cnt--;
if(cnt==0)
cnt=1;
int count=cnt;
cnt=a/count;
if(cnt>k)
cnt=k;
if(cnt==0)
cnt=1;
int temp=0;
while(a>0&&b>0)
{
cnt=b/k;
num=b*1.0/k;
if(num==cnt)
cnt--;
if(cnt==0)
cnt=1;
count=cnt;
cnt=a/count;
if(cnt>k)
cnt=k;
if(cnt==0)
cnt=1;
if(b>=k)
{
for(int i=0;i<k;++i)
str[temp++]='B';
b-=k;
}
else
{
for(int i=0;i<b;++i)
str[temp++]='B';
b-=b;
}
if(b==0)
cnt=k;
if(a>=cnt)
{
for(int i=0;i<cnt;++i)
str[temp++]='G';
a-=cnt;
}
else
{
for(int i=0;i<a;++i)
str[temp++]='G';
a-=a;
}
}
if(b>=k)
{
for(int i=0;i<k;++i)
str[temp++]='B';
b-=k;
}
else
{
for(int i=0;i<b;++i)
str[temp++]='B';
b-=b;
}
if(a!=0 || b!=0)
printf("NO\n");
else{
str[temp]='\0';
printf("%s\n",str);
}
}
}
return 0;
}

/*
10 4 9 1
10 5 5 5
10 3 5 5
16 3 8 8
16 2 4 12
15 3 5 10
15 3 4 11
20 2 12 8
*/


展开全文
• Green and Black Tea time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Innokentiy likes tea very much and to


D. Green and Black Tea

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard 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 ntea 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 thata + 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

题目大意：有红茶a包，黑茶b包，a+b=n，构造出一种方案使每种茶连续的数量不超过k，如果不存在合法方案就输出NO
题解：构造
这道题首先要考虑分成将两种茶分成了多少段。t=max(a/k,b/k)
然后根据段数计算出每段中a,b的数量，注意不能超过k，也不能小于1.
但是如果直接这么构造t段，最终剩余的a,b可能超过k，所以在构造的过程中我们要根据计算的剩余情况，更改每段中a,b的值。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,a,b;
int main()
{
scanf("%d%d%d%d",&n,&k,&a,&b);
int ta=(a)/k;
int tb=(b)/k;
if (a<(b-1)/k||b<(a-1)/k) {
printf("NO\n");
return 0;
}
int mark=0;
if (ta<tb) mark=1;
int t=max(ta,tb);
int sizea=k;
int sizeb=k;
if (t) sizea=max(1,min(sizea,a/t)),sizeb=max(1,min(sizeb,b/t));
for (int i=1;i<=t;i++)
{
if (!mark) {
for (int j=1;j<=min(sizea,a);j++) printf("G");
a-=sizea;
for (int j=1;j<=min(sizeb,b);j++) printf("B");
b-=sizeb;
while (a-sizea*(t-i)>k&&a-(sizea+1)*(t-i)>=0&&sizea<k)
sizea++;
while ((b-sizeb*(t-i)>k||a-sizea*(t-i)==0&&sizeb+b-sizeb*(t-i)>k)&&b-(sizeb+1)*(t-i)>=0&&sizeb<k)
sizeb++;
}
else {
for (int j=1;j<=min(sizeb,b);j++) printf("B");
b-=sizeb;
for (int j=1;j<=min(sizea,a);j++) printf("G");
a-=sizea;
while ((a-sizea*(t-i)>k||b-sizeb*(t-i)==0&&sizea+a-sizea*(t-i)>k)&&a-(sizea+1)*(t-i)>=0&&sizea<k)
sizea++;
while (b-sizeb*(t-i)>k&&b-(sizeb+1)*(t-i+1)>=0&&sizeb<k)
sizeb++;
}
}
if (!mark) {
for (int j=1;j<=max(0,a);j++) printf("G");
for (int j=1;j<=max(0,b);j++) printf("B");
}
else
{
for (int j=1;j<=max(0,b);j++) printf("B");
for (int j=1;j<=max(0,a);j++) printf("G");
}
}    


展开全文
• Green and Black Tea time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Innokentiy likes tea very much and to
• Green and Black Tea time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputInnokentiy likes tea very much and today he wants to drink exa
• 英美人发现英文中的black tea在汉语中的表达是“红茶”，而并非“黑茶”。大家都感到很有趣：black明明是黑，为什么在汉语中成了“红”呢？其实，这是一个很常见的语言现象。有颜色特点的事物虽然客观所指是同一的，...
• 大家好，我Blacktea这个是我菜鸟教程的第二篇 没有看过第一篇的请点击：菜鸟教程：BlackTea简谈IP及其应用！   教程开始： 上一节我已经讲过怎么获取自己和网站的ip地址  这一节我们讲一下获取他人的ip： ·方法...
• 为什么中文的“红茶”red tea 会变成了英文的“黑茶”black tea呢？历史上有各种版本的说法，有的接近真实，有的只是传说而已。一种说法是因为在红茶加工过程中，茶叶的颜色越来越深，逐渐变成黑色，因此得名Black...
• 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
• Green and Black Tea time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Innokentiy likes tea very much and to
• Green and Black Tea time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Innokentiy likes tea very much and today he wants to drink
• 我是BlackTea！ 很多黑客教程书的第一课就是IP的讲解，本人也看过不少教材，IP地址明显就是照着百度百科复制的，（给新手讲ip地址的分类用你？）额。。。。貌似废话多了点。。 好！言归正传！ 我们来理解一下ip是...
• Black tea 黑茶还是红茶？ 为什么中文的“红茶”red tea 会变成了英文的“黑茶”black tea呢？历史上有各种版本的说法，有的接近真实，有的只是传说而已。一种说法是因为在红茶加工过程中，茶叶的颜色越来越深，...
• Green and Black Teatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInnokentiy likes tea very much and today he wants to drink exactl...
• Green and Black Tea time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Innokentiy likes tea very much and today he wan
• 题目链接：http://codeforces.com/problemset/problem/746/D题解：题目大意：有一个人要喝a，b两种茶（总数为n），但是他有一个要求，不能连续喝同一种茶超过k次，让你输出满足条件的喝茶的过程。...
• 先搞多的，搞到相等。 （tmd上星期+上上星期简直是弱智，怎么也不会写，总是想着各种a/b，，，踢蹬） #include<bits/stdc++.h> #define lowbit(x) x&(-x) ...#define mod 2147483648...
• 这道题很有意思，意思让你生成一个喝茶的虚列，让这个序列中连续相同的片段长度不超过K。 首先考虑下无解的情况，如果多的那个(A)无法被分B（少的）+1段，那么无解，之后我们先把最下段的一个字符输出再判断要输出...
• Innokentiy likes tea very much and today he wants to drink exactlyncups of tea. He would be happy to drink more but he had exactlyntea bags,aof them are green andbare black. Innokentiy
• 题意:有n杯茶，a杯绿茶，b杯红茶，问怎么摆放才可以让不超过k杯一样的茶连续摆放，如果不能就输出NO。 //颜色少的Y至少要有n/(k+1)个 插入后如果还有剩下,则在每组里面隔一个间隔插入即可  ...
• 思路：先放多的，多的都是以k个连成一块，然后少的往里插。 #include using namespace std; char str[100005]; int main() { int n,k,a,b,flag; cin>>n>>k>>a>>b; char aa,bb; aa='G';... swap
• 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 ...
• 题意很明显不解释 做法就是直接模拟 有一个坑的地方就是中间值会爆ll WA50 1 #include<bits/stdc++.h> 2 #define cl(a,b) memset(a,b,sizeof(a)) 3 #define debug(a) cerr<... 4 usin...
• 首先说下一定是ＮＯ的情况。 假设ａ > b 那么，b最多能把a分成b + 1分，如果每份刚好是k的话，那么就最多能支持a的最大值是(b + 1) * k 其实就好比如，分成3分的话，x1 + x2 + x3 = m，每个xi <...
• By:blacktea 大飞哥把黑客分为了初、中、后三个阶段讲解。我就是给你们加个注释 在这里我给大家个建议：如果你只为了学习盗号，刷钻什么的，你最好还是找个可信的人 给两个钱让他 教你，黑客不是干那个的 ...
• 题意： 两种茶各有一定数量，放在一行，同一种不能连续放k个，问有没有合适的放置的方法。 思路： 最好就是间隔相等的放置，假设G比B多，一开始一个G一个B。一圈后，从头开始在每个G后面继续放G,直到没有G为止 ...
• 基于深度学习的近红外高光谱图像识别红茶贮藏年限 Abstract 储存多年的红茶可能会被掺假作为新鲜茶出售。将近红外高光谱成像与机器学习方法相结合，用于红茶贮藏年份的快速检测。对2016年、2017年、2018年和2019年...

...