CF1256A Payment Without Change
題目描述
You have aa coins of value nn and bb coins of value 11 . You always pay in exact change, so you want to know if there exist such xx and yy that if you take xx ( 0 \le x \le a0≤x≤a ) coins of value nn and yy ( 0 \le y \le b0≤y≤b ) coins of value 11 , then the total value of taken coins will be SS .
You have to answer qq independent test cases.
輸入格式
The first line of the input contains one integer qq ( 1 \le q \le 10^41≤q≤104 ) — the number of test cases. Then qq test cases follow.
The only line of the test case contains four integers aa , bb , nn and SS ( 1 \le a, b, n, S \le 10^91≤a,b,n,S≤109 ) — the number of coins of value nn , the number of coins of value 11 , the value nn and the required total value.
輸出格式
For the ii -th test case print the answer on it — YES (without quotes) if there exist such xx and yy that if you take xx coins of value nn and yy coins of value 11 , then the total value of taken coins will be SS , and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
輸入輸出樣例
輸入 #1復制
輸出 #1復制
題解:
題目大意:
你現在有\(a\)塊面值為\(n\)的錢幣和\(b\)塊面值為\(1\)的錢幣。現在給你一個目標價格\(S\),問你是否能夠用手中的錢幣湊出來想要的價格。
解析:
簡單的模擬。可以發現,因為有一塊錢的湊數,所以只要我們湊出來的\(n\)面值的錢的總價值比\(S\)小,而且小的那部分可以用一塊錢的補齊(即數量足夠),那么就顯然可以湊出合法的錢數。
那我們如何知道比\(S\)小的\(n\)面值的錢有多少呢?
除法啊。\(\lfloor s/n\rfloor\)。
注意,這里還需要和\(a\)比一下大小,因為有可能\(\lfloor s/n\rfloor>a\),這種情況是不合法的。
最后判一下這個東西加上\(b\)能不能比\(S\)大,大的話就合法,否則就非法。
至於輸出,還是建議大家放標准輸出\(YES\)和\(NO\)。養成好習慣。
代碼:
#include<cstdio>
#include<algorithm>
using namespace std;
int T;
int a,b,n,s;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d",&a,&b,&n,&s);
int num=s/n;
num=min(num,a);
if(num*n+b>=s)
{
printf("YES\n");
continue;
}
else
{
printf("NO\n");
continue;
}
}
return 0;
}