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 = ;
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 ;
}