hdu 5310 Souvenir(BestCoder 1st Anniversary ($))

http://acm.hdu.edu.cn/showproblem.php?pid=5310

题目大意:要买n个纪念品,可以单个买p元每个,可以成套买q元一套,每套有m个,求最少花费

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define N 110

using namespace std;

int main()
{
    int t, sum, n, m, p, q, a, b;
    scanf("%d", &t);
    while(t--)
    {
        sum = 0;
        scanf("%d%d%d%d", &n, &m, &p, &q);
        a = n / m;
        b = n % m;
        if((n - b) * p > a * q)
            sum += a * q;
        else
            sum += (n - b) * p;
        if(b * p > q)
            sum += q;
        else
            sum += b * p;
        printf("%d
", sum);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/qq2424260747/p/4778267.html