首页 > 其他 > 详细

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

时间:2021-04-30 10:23:49      阅读:29      评论:0      收藏:0      [点我收藏+]

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;
}

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

原文:https://www.cnblogs.com/lipoicyclic/p/14720708.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!