D. Green and Black Tea 贪心 + 构造
2024-09-03 15:02:51
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 ;
}
最新文章
- 父子页面之间元素相互操作(iframe子页面)
- acm入门 杭电1001题 有关溢出的考虑
- webService-cxf
- WebAPI的初步认识(CURD)
- CruiseControl.NET/CCNET安装包下载
- Javascript算术运算
- bootstrap-4
- 数据库知识整理<;三>;
- 深入理解BootStrap之栅格系统(布局)
- Git 基础应用
- AndroidUI组件之ActionBar--基于下拉的导航方式
- Oracle游标
- 201521123093 java 第十二周学习总结
- java中自动装箱带来的性能问题
- GeoJSON C#判断某一点是否在某一区域范围之内
- MySQL数据库学习三 数据库对象和基本操作
- html与ios交互方法 WebViewJavascriptBridge
- 合肥工业大学oj p1012
- SpringBoot的学习【6.YML 和 Properties 的语法】
- 深入理解Redis复制
热门文章
- JAVA学习第六十四课 — 反射机制
- Xcode The identity used to sign the executable is no longer valid. 错误解决
- Android之键盘监听的执行机理【看清键盘监听的本质】【入门版】
- 关于集成支付宝SDK的开发
- win10访问共享文件夹提示:引用的账户当前已锁定,且当前可能无法登陆
- java定时器2-spring实现
- HDU2819 Swap —— 二分图最大匹配
- web项目开发 之 前端规范 --- HTML编码规范
- 并不对劲的bzoj4825:loj2018:p3721:[HNOI2017]单旋
- 虚拟机C盘扩容