原题目:
Problem Description
Alice boldly asserts to you that if you divide m items into n groups, there will definitely be one group with a quantity of items greater than or equal to d.
Due to Alice's excessive self-confidence, she is unaware that some of her assertions are actually incorrect. Your task is to determine whether Alice's assertion is correct. If Alice's assertion is true, output 'Yes'; otherwise, output 'No'.
Input
The input consists of multiple test cases. The first line contains a single integer T(1≤T≤105) — the number of test cases. Description of the test cases follows.
The first line of each test case contains three integers n,m,d (2≤m≤10^9,1≤n<m,0≤d≤10^9),n and m represent the number of groups and the quantity of items, respectively, in Alice's assertion. The symbol d signifies Alice's claim that there will always be at least one group with a quantity of items greater than or equal to d.
Output
For each set of data, output a string. If Alice's assertion is correct, output 'Yes'; otherwise, output 'No'.
Sample Input
3
1 2 1
2 3 2
3 10 4
Sample Output
Yes
Yes
Yes
翻译:
输入由多个测试用例组成。第一行包含单个整数T(1<=t<=10^5)测试用例的数量。下面是测试用例的描述。
每个测试用例的第一行包含三个整数n,m,d (2<=m<=10^9,1<= n<m,0<=d<=10^9),n和m分别表示Alice断言中的组数和项数。符号d表示Alice的断言,即总有至少一个组的项目数量大于或等于d。
输入由多个测试用例组成。第一行包含单个整数T(1<=t<=10^5)测试用例的数量。下面是测试用例的描述。
每个测试用例的第一行包含三个整数n,m,d (2<=m<=10^9,1<=n<m,0<=d<=10^9),n和m分别表示Alice断言中的组数和项数。符号d表示Alice的断言,即总有至少一个组的项目数量大于或等于d。
对于每组数据,输出一个字符串。如果Alice的断言是正确的,输出'Yes';否则,输出“No”。
思路:
可以想象为:将V升的水装入n个杯子,是否一定存在某个杯子内的水>=d升,首先求的每个杯子内的水的平均值V/n,若有余数k,k一定小于V/n,所以部分杯子内装水V/n+1,最后判断它与d的大小关系。
解决方案:
项目数除以组数,得到平均值,如果整除,则直接与d比较大小,如果不整除,则平均值+1再与d比较大小,大于则必定存在。
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,n,m,d;
cin>>t;
while(t--)
{
scanf("%d %d %d",&n,&m,&d);//cin会超时
if(m%n==0&&m/n>=d)
{
printf("Yes\n");//cout会超时
}
else if(m%n!=0&&m/n+1>=d)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
}
return 0;
}