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. Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)

    传送门 A. Optimal Currency Exchange 枚举一下就行了. Code #include <bits/stdc++.h> using namespace std; t ...

  2. Python Django,事务,transaction.atomic,事务保存点

    from django.shortcuts import renderfrom django.http import HttpResponsefrom django.views.generic imp ...

  3. 设计模式-Template(行为模式) 采用 继承的方式 将算法封装在抽象基类中,在子类中实现细节。利用面向对象中的多态实现算法实现细节和高层接口的松耦合。

    以下代码来源: 设计模式精解-GoF 23种设计模式解析附C++实现源码 //Template.h class AbstractClass { public: virtual ~AbstractCla ...

  4. C语言的指针用法:输入一堆字符,把非字母的删去。

    char *p,a[20]; int i; gets(a);    //这个语句不同于getchar(),后者只能一次输入一个,而前者可以一次输完所有的字符!!! p=a;        //这个语句 ...

  5. 【python爬虫】初识爬虫

    一.爬虫的定义 爬虫定义:程序或者脚本——自动的爬取万维网的数据的程序或者脚本. 二.爬虫可以解决的问题 1.解决冷启动问题. 2.搜索引擎的根基——通用爬虫. 3.帮助机器学习建立知识图谱. 4.制 ...

  6. 【51nod1253】Kundu and Tree(容斥+并查集)

    点此看题面 大致题意: 给你一棵树,每条边为黑色或红色, 求有多少个三元组\((x,y,z)\),使得路径\((x,y),(x,z),(y,z)\)上都存在至少一条红色边. 容斥 我们可以借助容斥思想 ...

  7. php date获取前一天的时间

    结果: 结论: 第二种方式只使用了一个函数,所以更快一些,速度大约是第一种的两倍

  8. Spring的增强模式

    一.前置增强 1.IdoSomeService 2.IdoSomeServiceImpl类实现IdoSomeService接口 3.MyBeforeAdvice 实现前置增强方法 4.applicat ...

  9. 使用Kafka建立可靠的高性能分布式消息传递基础结构

    在优锐课学习中了解到,我们可以看到实施资源适配器以将Kafka与企业Java解决方案集成.码了很多专业的相关知识, 分享给大家参考学习. 由于世界已经变得移动化,因此应用程序现在必须实时提供数据. 不 ...

  10. 2019_JAVA面试题_真实总结

    来自刚被某互联网公司录取的朋友的分享. 整理的面试题1: 1.Java里面有哪几种基础数据类型, 2.Char为何是两个字节, 3.Object有哪些方法 4.final修饰变量,函数,类的作用, 5 ...