HDU 5310 Souvenir (simple question)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.