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

63 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

@TOC

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 rr red and bb 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 tt (1t10001 \le t \le 1000) — the number of test cases.

The first and only line of each test case contains three integers rr, bb, and dd (1r,b1091 \le r, b \le 10^9; 0d1090 \le d \le 10^9) — 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 11 red and 11 blue bean. The absolute difference 11=0d|1 - 1| = 0 \le d.

In the second test case, you can form two packets: 11 red and 44 blue beans in the first packet and 11 red and 33 blue beans in the second one.

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

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


题目大意

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


解题思路

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

注意事项

C语言记得用 longlonglong long1r,b1091 \le r, b \le 10^9; 0d1090 \le d \le 10^9rdr*d可能大于INT_MAXINT\_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;
}

同步发文于我的CSDN,原创不易,转载请附上原文链接哦~
Tisfy:letmefly.blog.csdn.net/article/det…