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\n", sum);
    }
    return 0;
}

 

posted @ 2015-09-02 12:48  午夜阳光~  阅读(176)  评论(1编辑  收藏  举报