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. Ubuntu 18.04 安装 pip3

    Ubuntu 18.04 默认安装了 python2.x 和 python3.x:默认情况下 python 指的是 python2.x,如果要使用 python3.x 需要使用 python3,如: ...

  2. python 编程2

    一.课堂练习 描述 使用input输入若干个数,输出个数以及其中最大的数 1.普通方法实现 def max(*a): m=a[0] b=0 for x in a: if x>m: m=x b+= ...

  3. Codeforces Round 596 题解

    万幸的是终于碰上了一场上分好场. 不幸的是一开始差点不会 A. 万幸的是想了个不那么稳的结论过了 pretest. 不幸的是罚时很高,而且慌得一比. 万幸的是然后半个小时内把 B 和 C 码了. 不幸 ...

  4. 《细说PHP》第四版 样章 第23章 自定义PHP接口规范 11

    23.6  使用第三方接口服务实例 接供服务的第三方接口平台有很多,现在的项目中也经常用到一些第三方接口,如支付宝.微信.短信.邮件接口等,我们需要借助第三方的能力来实现产品的某些功能.如果自己已经掌 ...

  5. apt-get failed:The following signatures were invalid: BADSIG

    参考如下链接: https://askubuntu.com/questions/131601/gpg-error-release-the-following-signatures-were-inval ...

  6. 面试必问的Spring IOC详解

    广义的 IOC IoC(Inversion of Control) 控制反转,即“不用打电话过来,我们会打给你”. 两种实现: 依赖查找(DL)和依赖注入(DI). IOC 和 DI .DL 的关系( ...

  7. 【学习笔记】动态规划—各种 DP 优化

    [学习笔记]动态规划-各种 DP 优化 [大前言] 个人认为贪心,\(dp\) 是最难的,每次遇到题完全不知道该怎么办,看了题解后又瞬间恍然大悟(TAT).这篇文章也是花了我差不多一个月时间才全部完成 ...

  8. Four Ways to Read Configuration Setting in C#(COPY)

    Introduction This article will demonstrate us how we can get/read the configuration setting from Web ...

  9. Python制作动态二维码只需要一行代码!炒鸡简单!

    分享一个比较有意思的项目,只需要一行Python代码就可以快捷方便生成普通二维码.艺术二维码(黑白/彩色)和动态GIF二维码. 用法比较简单,直接通过pip安装即可. pip3 install myq ...

  10. 易优CMS:type的基础用法

    [基础用法] 名称:type 功能:获取指定栏目信息 语法: {eyou:type typeid='栏目ID' empty='暂时没有数据'} <a href="{$field.typ ...