This is a little careful thinking can be made out of the simple question, and I wa two times, this is the reason for it to write up, just because I did not seriously think, or is not careful ah, or very careless ah, can not panic, have to carefully read the question, slowly.
Ideas:
There are only a few cases: 1 all with unit price P buy, 2 all with Set Q Buy, 3 first buy with a suit, the rest of the price p buy
Note: Do not have to determine the first use of unit price p re-use Set (if the first use of p to prove that the unit price is more cost-effective than the package (buy the same amount of money required))
Post code:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm>using namespace Std;int Main () {int t,n,m,p,q;scanf ("%d", &t), while (T--) {scanf ("%d%d%d%d", &n,&m,&p,&q); int ans, ans1,ans2,ans3;ans1 = P*n;if (n%m==0) ans2 = N/m*q;elseans2 = (n/m+1) *q;ans3 = n/m*q + N%m*p;ans = min (Ans1,min (ans2,an S3));p rintf ("%d\n", ans);} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 5310 Souvenir (simple question)