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

Posted Tisfy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

以上是关于Educational Codeforces Round 108 (Rated for Div. 2)-A. Red and Blue Beans-题解的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27