Codeforces 746D:Green and Black Tea(乱搞)

时间:2023-03-09 18:01:51
Codeforces 746D:Green and Black Tea(乱搞)

http://codeforces.com/contest/746/problem/D

题意:有n杯茶,a杯绿茶,b杯红茶,问怎么摆放才可以让不超过k杯茶连续摆放,如果不能就输出NO。

思路:首先,设x = min(a,b),y = max(a,b),然后如果(y + x)/(x + 1) > k,那么就输出NO。即把 y 平均分成 x + 1 份,向上取整。然后开始搞。。。

搞的时候我直接对于 y 每一次都输出最大的份数了,导致后面的 x 过多,还自以为是平均的。

所以应该处理一下,如果有剩余的话,那么剩余的数目是 cnt = y % (x + 1),就是在 a + 1 组 y 里面,有 cnt 组是要多输出一个的,其他的只要输出 y / (x + 1)个就可以了。

细心细心!!!

 #include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define INF 0x3f3f3f3f
#define N 200010
typedef long long LL; char s[N]; int main() {
int n, k, a, b;
cin >> n >> k >> a >> b;
char c = 'G', d = 'B';
if(a >= b) {
swap(a, b);
swap(c, d);
}
int x = b / (a + );
int y = x + (b % (a + ) ? : );
if(y > k) puts("NO");
else {
int j = ;
for(int i = ; i < a + ; i++) {
if(i) putchar(c);
int cnt = x + ((i < b % (a + )) ? : );
for(int q = ; q < cnt; q++) putchar(d);
}
puts("");
}
return ;
}