Souvenir
Total Submission(s): 704 Accepted Submission(s): 430
There's n contestants in the contest today. Soda wants to know the minimum cost needed to buy a souvenir for each contestant.
There's a line containing 4 integers n,m,p,q (1≤n,m,p,q≤104) .
2 1 2 2 1 1 2 3 4
1 3HintFor the first case, Soda can use 1 yuan to buy a set of 2 souvenirs. For the second case, Soda can use 3 yuan to buy a souvenir.
注意边界情况
#include<stdio.h>
#include<math.h>
int main()
{
int t,n,m,p,q,yu,sum;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
sum=0;
scanf("%d%d%d%d",&n,&m,&p,&q);
if(p*m<=q)
{
sum=p*n;
}
else
{
yu=n%m;
if(yu*p<=q)
{
sum=n/m*q+yu*p;
}
else
sum=(n/m+1)*q;
}
printf("%d\n",sum);
}
}
return 0;
}
669



被折叠的 条评论
为什么被折叠?



