CF598 div3 A. Payment Without Change(贪心)

A. Payment Without Change

在这里插入图片描述
题目的意思是有a个价值为n和b个价值为1的硬币,能否用他们组成S
贪心选择,总是尽可能用价值大的硬币,因为另外一个是1.然后判断剩余值是否比b大就行辽

#include <bits/stdc++.h>

using namespace std;
int a,b,n,S;
int main()
{
    
    
    int t;
    cin>>t;
    while(t--){
    
    
        cin>>a>>b>>n>>S;
        if(S-min(S/n,a)*n>b) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43329358/article/details/102964104