Educational Codeforces Round 108 (Rated for Div. 2)-A. Red and Blue Beans-题解

Educational Codeforces Round 108 (Rated for Div. 2)-A. Red and Blue Beans

传送门
Time Limit: 1 second
Memory Limit: 256 megabytes

Problem Description

You have r r r red and b b b blue beans. You’d like to distribute them among several (maybe, one) packets in such a way that each packet:

Can you distribute all beans?

Input

The first line contains the single integer t t t ( 1 ≤ t ≤ 1000 1 \le t \le 1000 1t1000) — the number of test cases.

The first and only line of each test case contains three integers r r r, b b b, and d d d ( 1 ≤ r , b ≤ 1 0 9 1 \le r, b \le 10^9 1r,b109; 0 ≤ d ≤ 1 0 9 0 \le d \le 10^9 0d109) — 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).

Sample Input

4
1 1 0
2 7 3
6 1 4
5 4 0

Sample Onput

YES
YES
NO
NO

Note

In the first test case, you can form one packet with 1 1 1 red and 1 1 1 blue bean. The absolute difference ∣ 1 − 1 ∣ = 0 ≤ d |1 - 1| = 0 \le d 11=0d.

In the second test case, you can form two packets: 1 1 1 red and 4 4 4 blue beans in the first packet and 1 1 1 red and 3 3 3 blue beans in the second one.

In the third test case, since b = 1 b = 1 b=1, you can form only one packet with 6 6 6 red and 1 1 1 blue beans. The absolute difference ∣ 6 − 1 ∣ = 5 > d |6 - 1| = 5 > d 61=5>d.

In the fourth test case, since d = 0 d = 0 d=0 so each packet should contain the same number of red and blue beans, but r ≠ b r \neq b r=b.


题目大意

给你 r r r个红豆和 b b b个蓝豆 (为啥不是绿豆我也不知道) 放入一些盒子中,每个盒子里至少一个红豆一个蓝豆,且红豆和蓝豆的个数相差不能超过 d d d
给你 r 、 b 、 d r、b、d rbd,问你能不能实现这样的放法。


解题思路

  • 红豆和蓝豆的个数本来就相等的话肯定没问题,红豆和蓝豆的个数之差是 0 0 0一定 ≤ d \leq d d
  • 若红豆和蓝豆的个数不同(假设红豆少一些(如果是蓝豆少的话话就交换他们的值)),就需要有些盒子中红豆比蓝豆少。题目限制一个盒子中红豆比蓝豆最多少 d d d个,所以就把个红豆放到尽可能多的盒子中。一个盒子只放一个红豆,最多就可以放 1 + d 1+d 1+d个蓝豆。所有盒子( r r r个)最多可以放 r ∗ ( 1 + d ) r*(1+d) r(1+d)个蓝豆。如果蓝豆多于 r ∗ ( 1 + d ) r*(1+d) r(1+d),就不能实现这样的放置方法;否则可以。

注意事项

C语言记得用 l o n g l o n g long long longlong 1 ≤ r , b ≤ 1 0 9 1 \le r, b \le 10^9 1r,b109; 0 ≤ d ≤ 1 0 9 0 \le d \le 10^9 0d109 r ∗ d r*d rd可能大于 I N T _ M A X INT\_MAX INT_MAX

AC代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
        ll r,b,diff;
        cin>>r>>b>>diff;
        if(r>b)swap(r,b);//假设红豆少。如果蓝豆比红豆少,就交换他们的值
        if(r*(diff+1)>=b)puts("YES");
        else puts("NO");
    }
    return 0;
}

原创不易,转载请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/116330689

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tisfy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值