zoukankan      html  css  js  c++  java
  • CF1256A Payment Without Change

    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 floor)

    注意,这里还需要和(a)比一下大小,因为有可能(lfloor s/n floor>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
    ");
                continue;
            }
            else 
            {
                printf("NO
    ");
                continue;
            }
        }
        return 0;
    }
    
  • 相关阅读:
    [leetcode-551-Student Attendance Record I]
    [leetcode-543-Diameter of Binary Tree]
    [leetcode-541-Reverse String II]
    [leetcode-530-Minimum Absolute Difference in BST]
    [leetcode-521-Longest Uncommon Subsequence I]
    [leetcode-504-Base 7]
    [leetcode-116-Populating Next Right Pointers in Each Node]
    [leetcode-573-Squirrel Simulation]
    [leetcode-572-Subtree of Another Tree]
    [leetcode-575-Distribute Candies]
  • 原文地址:https://www.cnblogs.com/fusiwei/p/11796097.html
Copyright © 2011-2022 走看看