CF1256A Payment Without Change
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;
}
相关文章
- What Causes Stock Prices to Change?
- Method overrides should not change parameter defaults
- CodeForcesGym 100753E Change of Scenery
- PowerShell: Change default editor for PowerShell
- Disable NUMA & Change I/O Scheduler
- How to Change the default kernel (boot from old kernel) in CentOS/RHEL 8
- Online Schema Change for MySQL
- UVaLive 7503 Change (坑题。。。。。。)
- SAP MM: Change of material moving average price after goods receipt and invoice verification posting for PO
- Dynamic CRM 2013学习笔记(二十八)用JS动态设置字段的change事件、必填、禁用以及可见
- jq select change下拉框选项变化判断选中值,添加(attr)或移除(removeAttr)一个或多个属性
- Cannot change version of project facet Dynamic web module to 2.5
- MatLab GUI Change Size 改变界面大小