Educational Codeforces Round 108 (Rated for Div. 2) A. Red and Blue Beans(思维)
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:
- has at least one red bean (or the number of red beans ri≥1);
- has at least one blue bean (or the number of blue beans bi≥1);
- the number of red and blue beans should differ in no more than 𝑑d (or |ri−bi|≤d)
Can you distribute all beans?
Input
The first line contains the single integer 𝑡t (1≤t≤1000) — the number of test cases.
The first and only line of each test case contains three integers r, b, and d (1≤r,b≤109; 0≤d≤109) — the number of red and blue beans and the maximum absolute difference in each packet.
Output
For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
input
Copy
4
1 1 0
2 7 3
6 1 4
5 4 0
output
Copy
YES
YES
NO
NO
不妨设r > b,首先求出来r和b的差值,然后贪心地分配(先保证每个包红蓝个数都是b,然后把多的r平均分配,看看能否满足条件即可。
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--) {
long long r, b, d;
cin >> r >> b >> d;
long long x = min(r, b), diff = abs(r - b);
if(ceil(diff * 1.0 / x) <= d) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!