codeforce 386(div2) D. Green and Black Tea
来源:互联网 发布:股市交易软件 编辑:程序博客网 时间:2024/06/03 04:05
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.
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.
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.
这边比如a==0或b==0是比较容易判断的。(两个不能同时为零,因为n>=1)
a==b就是间隔的输出。
这边假设a>b,(与a<b的情况是一样的),拿最优的情况就是a平均分成b+1份,如果有余数的话就是某几项要加1,判断是否会超过k
然后就是模拟了;
AC代码:
#include<stdio.h>#include<iostream>#include<vector>#include<queue>#include<algorithm>using namespace std;typedef long long int ll;int main() {int i, j, k, a, b, n;//a--G, b--Bscanf("%d%d%d%d", &n, &k, &a, &b);//for (i = 1; i <= n; i++)if (a == 0) {if (k >= b) {for (i = 1; i <= b; i++) {printf("B");}}else {printf("NO");}}else if (b == 0) {if (k >= a) {for (i = 1; i <= a; i++) {printf("G");}}else {printf("NO");}}else {if (a == b) {for (i = 1; i <= a; i++) {printf("GB");}}else if (a > b) {int mod = a%(b+1), t=a/(b+1);if (mod == 0) {if (t <= k) {for (i = 1; i <= b + 1; i++) {if (i != b + 1) {for (j = 1; j <= t; j++) {printf("G");}printf("B");}else {for (j = 1; j <= t; j++) {printf("G");}}}}else {printf("NO");}}else {if (t + 1 > k) {printf("NO");return 0;}for (i = 1; i <= mod; i++) {for (j = 1; j <= t + 1; j++) {printf("G");}printf("B");}for (i = mod + 1; i <= b + 1; i++) {if (i != b + 1) {for (j = 1; j <= t; j++) {printf("G");}printf("B");}else {for (j = 1; j <= t; j++) {printf("G");}}}}}else {int mod = b % (a + 1), t = b / (a + 1);if (mod == 0) {if (t <= k) {for (i = 1; i <= a + 1; i++) {if (i != a + 1) {for (j = 1; j <= t; j++) {printf("B");}printf("G");}else {for (j = 1; j <= t; j++) {printf("B");}}}}else {printf("NO");}}else {if (t + 1 > k) {printf("NO");return 0;}for (i = 1; i <= mod; i++) {for (j = 1; j <= t + 1; j++) {printf("B");}printf("G");}for (i = mod + 1; i <= a + 1; i++) {if (i != a + 1) {for (j = 1; j <= t; j++) {printf("B");}printf("G");}else {for (j = 1; j <= t; j++) {printf("B");}}}}}}return 0;}
- codeforce 386(div2) D. Green and Black Tea
- codeforces #386 div2 D. Green and Black Tea
- Codeforces Round #386 (Div. 2)D. Green and Black Tea
- Codeforces Round #386 (Div. 2) D. Green and Black Tea
- CodeForces 746D Green and Black Tea
- codefroces 746D Green and Black Tea
- 746 D. Green and Black Tea codeforces
- 746D Green and Black Tea
- 【21.58%】【codeforces 746D】Green and Black Tea
- 【Codeforces 746D Green and Black Tea】+ 构造
- Codeforces 746D Green and Black Tea(构造)
- codeforces 746 D. Green and Black Tea (构造)
- Codeforces 746D Green And Black Tea 构造
- Codeforces Round #386(Div. 2)D. Green and Black Tea【思维+构造】
- Codeforces Round #386 (Div. 2) D. Green and Black Tea 数论+贪心
- Codeforces Round #386 (Div. 2) 746D Green and Black Tea
- codeforce Pasha and Tea
- codeforce 241div2 D
- pycharm-professional-201603 注册码
- 输出名称为连续数字的图片
- Android 系列 5 图形
- node.js文件的复制,创建文件夹等相关操作
- Qt 批量打印图片
- codeforce 386(div2) D. Green and Black Tea
- Java函数式开发——优雅的Optional空指针处理
- Apache和Tomcat,两种服务器的联系
- IOS调试的时候无dSYM 出现crash如何分析
- c#委托与事件
- 解决Maven工程中报 Missing artifact jdk.tools:jdk.tools
- AutoCAD 二次开发
- 用Groovy思考 第一章 用Groovy简化Java代码
- c++primer plus 第六版第四章编程习题