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 exact change, so you want to know if there exist such x and y that if you take x (0≤x≤a) coins of value n and y (0≤y≤b) coins of value 1, then the total value of taken coins will be S.
You have to answer q independent test cases.
Input
The first line of the input contains one integer q (1≤q≤104) — the number of test cases. Then q test cases follow.
The only line of the test case contains four integers a, b, n and S (1≤a,b,n,S≤109) — the number of coins of value n, the number of coins of value 1, the value n and the required total value.
Output
For the i-th test case print the answer on it — YES (without quotes) if there exist such x and y that if you take x coins of value n and y coins of value 1, then the total value of taken coins will be S, 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).
Example
input
4
1 2 3 4
1 2 3 6
5 2 6 27
3 3 5 18
output
YES
NO
NO
YES
题意
你有a个价值为n的硬币,你有b个价值为1的硬币,问你能否组成S块钱。
题解
贪心,能用a就用a对吧
代码
#include<bits/stdc++.h>
using namespace std;
void solve(){
long long a,b,n,s;
cin>>a>>b>>n>>s;
long long d = s/n;
d=min(d,a);
if(b>=s-d*n){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
int main(){
int t;
scanf("%d",&t);
while(t--)solve();
}
最新文章
- Windows Azure Virtual Machine (30) 修改Azure VM 的Subnet
- OpenGL 纹理贴图
- uva 11324 The Largest Clique (Tarjan+记忆化)
- hdu 5046 Airport 二分+重复覆盖
- iOS App3D Touch快捷键的静态以及动态设置详细使用
- MyEclipse提示
- C#迭代语句、跳转语句--C#基础
- 机器学习(1) - TensorflowSharp 简单使用与KNN识别MNIST流程
- Gson序列化对象如何忽略字段
- Windows下createfile函数用GENERIC_READ访问模式打不开磁盘
- 如何使用Docker部署一个Go Web应用程序
- JavaScript对象的指向问题
- sonar-代码扫描
- OO第一单元三次作业总结
- el表达式获取对象属性值 返回值类型
- Java 静态方法不能重写但可以被子类静态方法覆盖
- STM32 SPI接口的NSS引脚
- ASP.NET Core 2.0 MVC 发布部署--------- linux安装.NET CORE SDK具体操作链接以及操作总细节
- css实现图标移上图标弹跳效果
- 安装mezzanine时报:storing debug log for failure【已解决】
热门文章
- js-01-基础知识
- 云K8S - AWS容器库ECR(ERS)编排ECS-EKS以及阿里云编排ACS-ACK
- redis5.0.0功能介绍以及主从集群、哨兵搭建
- C#后台架构师成长之路-基础体系篇章大纲
- vue element-ui父列表和子列表同时出现时的bug
- 设计模式-工厂模式(Factory)(创建型模式)
- Python 分析到底是谁操纵《庆余年》上了热搜?
- 【RTOS】为H7配套的uCOS-III模板也是可以用于MDK AC6的,提供个模板
- IT兄弟连 HTML5教程 多媒体应用 小结及习题
- 基于appium的fixture应用之代码重构