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≤xa ) coins of value nn and yy ( 0 \le y \le b0≤yb ) 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;
}

CF1256A Payment Without Change的更多相关文章

  1. CF1256A Payment Without Change 题解

    OI生涯打的第一场CF比赛,写篇题解纪念一下吧 ------------可以想到先尽量用面值为1的硬币来凑,然后再用面值为n的硬币来补足.先算出用上所有面值为1的硬币还差多少钱,然后判断用面值为n的硬 ...

  2. Codeforces Round #598 (Div. 3) A. Payment Without Change 水题

    A. Payment Without Change You have a coins of value n and b coins of value 1. You always pay in exac ...

  3. input text文本框内部最后面放一个按钮

    .ContSpan { border: 1px solid #; display: inline-block; } .ContSpan span { cursor: pointer; backgrou ...

  4. Codeforces Round #598 (Div. 3)

    传送门 A. Payment Without Change 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/4 21:19:19 */ #i ...

  5. Codeforces 1256A 1257A

    题目链接:https://codeforces.com/problemset/problem/1256/A A. Payment Without Change time limit per test ...

  6. CF598: div3解题报告

    CF598:div3解题报告 A: Payment Without Change 思路: 按题意模拟即可. 代码: #include<bits/stdc++.h> using namesp ...

  7. SAP T CODE : Description (Program)

    SAP T CODE : Description (Program) V : Quickstart RKCOWUSL (RKCOWUSL)V+01 : Create Sales Call (SAPMV ...

  8. Codeforces Round #598 (Div. 3) A,B,C,D{E,F待补}

    A. Payment Without Change   #include<bits/stdc++.h> using namespace std; #define int long long ...

  9. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

随机推荐

  1. PHP 自带的验证函数 FILTER_VAR()

    常见的用法 检查邮箱的格式是否合法 if (filter_var('bob@example.com', FILTER_VALIDATE_EMAIL)) { } 更多相关的 过滤参数: ID 名称 描述 ...

  2. redis在centos7下安装(源码编译)

    下载 地址:http://www.redis.cn/download.html 下载稳定版本 把安装包上传到服务器 linux下安装 解压 进入解压后的目录,编译 创建目录,安装并指定目录 修改配置 ...

  3. LeetCode 1244. 力扣排行榜

    地址 https://www.acwing.com/solution/LeetCode/content/5765/ 题目描述新一轮的「力扣杯」编程大赛即将启动,为了动态显示参赛者的得分数据,需要设计一 ...

  4. autocad2014一直显示正在检查许可

    64位CAD2014安装成功后启动时在检查许可卡住的解决方法,以下方法经本人测试,真实可行.1.下载CCcleaner.2.将CCcleaner设置成中文版,英文好的继续第三步.(设置方法:选项opt ...

  5. 集成Hive和HBase

    1. MapReduce 用MapReduce将数据从本地文件系统导入到HBase的表中, 比如从HBase中读取一些原始数据后使用MapReduce做数据分析. 结合计算型框架进行计算统计查看HBa ...

  6. 大话设计模式Python实现-解释器模式

    解释器模式(Interpreter Pattern):给定一个语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言中的句子. 下面是一个解释器模式的demo: #!/usr/ ...

  7. linq根据两个时间求出天数

    对于在Linq To Entity里使用日期函数需要DbFunctions里的扩展方法,而不能使用.net里的日期函数,因为linq的代码会被翻译成SQL发到数据库端,如你的.net方法对于数据库是不 ...

  8. PHP7.1.X+wordpress+windows,安装Memcached服务

    1.下载安装Memcached 64位系统1.4.4版本:memcached-win64-1.4.4-14.zip 2.解压缩在任意盘符,然后进入文件夹,在文件夹中运行CMD输入以下命令: 1)输入 ...

  9. 【UOJ#310】【UNR#2】黎明前的巧克力(FWT)

    [UOJ#310][UNR#2]黎明前的巧克力(FWT) 题面 UOJ 题解 把问题转化一下,变成有多少个异或和为\(0\)的集合,然后这个集合任意拆分就是答案,所以对于一个大小为\(s\)的集合,其 ...

  10. nodejs通过钉钉群机器人推送消息

    nodejs 通过钉钉群机器人推送消息 Intro 最近在用 nodejs 写爬虫,之前的 nodejs 爬虫代码用 js 写的,感觉可维护性太差,也没有智能提示,于是把js改用ts(typescri ...