博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
D. Green and Black Tea 贪心 + 构造
阅读量:4607 次
发布时间:2019-06-09

本文共 1251 字,大约阅读时间需要 4 分钟。

首先说下一定是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 
#include
#include
#include
#include
#include
#define IOS ios::sync_with_stdio(false)using namespace std;#define inf (0x3f3f3f3f)typedef long long int LL;#include
#include
#include
#include
#include
#include
#include
void pr(int k, char ch) { for (int i = 1; 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) + 1) < max(a, b)) { cout << "NO" << endl; return; } int to = 0; int has = 0; if (a > b) { while (to < n) { if (a > b && has < k) { printf("G"); has++; a--; to++; } else { printf("B"); b--; has = 0; to++; } } } else { while (to < n) { if (b > a && has < k) { printf("B"); has++; to++; b--; } else { printf("G"); has = 0; to++; a--; } } }}int main() {#ifdef local freopen("data.txt", "r", stdin);// freopen("data.txt", "w", stdout);#endif work(); return 0;}
View Code

 

转载于:https://www.cnblogs.com/liuweimingcprogram/p/6195960.html

你可能感兴趣的文章
《EMCAScript6入门》读书笔记——14.Promise对象
查看>>
CSS——水平/垂直居中
查看>>
Eclipse连接mysql数据库jdbc下载(图文)
查看>>
快速入门
查看>>
Mybatis通过ID查询 && 通过name模糊查询
查看>>
发送邮件
查看>>
VirtulBox虚拟机搭建Linux Centos系统
查看>>
djang-异步——定时操作
查看>>
创建型模式(二):AbstractFactory ( 抽象工厂 )
查看>>
PHP获取当日或本月时间戳范围
查看>>
一款由jQuery实现的手风琴式相册图片展开效果
查看>>
基于jQuery仿淘宝产品图片放大镜代码
查看>>
Python中Selenium的使用方法
查看>>
python ord()与chr()用法以及区别
查看>>
三月23日测试Fiddler
查看>>
20171013_数据库新环境后期操作
查看>>
poj 1654 && poj 1675
查看>>
运维派 企业面试题1 监控MySQL主从同步是否异常
查看>>
Docker 版本
查看>>
poj 1753 Flip Game
查看>>