【数论】计算s里有几个n,去除s里的n

目录

题目

一些话

正篇


题目

你身上有 aa 个 nn 元的硬币和 bb 个 11 元的硬币。请问能不能在不找零的情况下购买 ss 元的物品。

Input

第一行一个数 qq (1 \le q \le 10^41≤q≤104) —代表有 qq 组数据

测试案例的只有一行包含四个整数 aa, bb, nn 和 SS (1 \le a, b, n, S \le 10^91≤a,b,n,S≤109) — 价值nn的硬币数量,价值11的硬币数量,价值nn和所需的总价值

Output

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

Sample 1

InputcopyOutputcopy
4
1 2 3 4
1 2 3 6
5 2 6 27
3 3 5 18
YES
NO
NO
YES

一些话

t了一发,nnd


正篇

原因是题目考察的套路不熟悉,拆分下这道题

t组数据,while(t--) 注意每一组用到的数据要初始化

计算可以用几个n元来支付(就是这点了,套路不熟练只想到模拟)↓

1.前提条件:

                要计算s里有几个n

套路:

                int cnt = s / n;

2.前提条件:

                去除s里的n

套路:

                以上一个套路为基础

                s -= (cnt) * n;

                因为n的数量是有限制的,如果减多了就补回多的部分;

                        if(cnt > a)

                        s+= (cnt - a) * n; 

                到这里这道题基本就搞定了,

下面是完整代码

#include <iostream>
using namespace std;


int main(){
    int t,a,b,n,s;
    cin >> t;
    while(t--){
        int cnt = 0;
        cin >> a>> b >> n >> s;
        cnt = s/n;
        s -= cnt * n;
        if(cnt > a){
            s += (cnt-a) * n;
        }

        
        if(s - b > 0) puts("NO");
        else puts("YES");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值