Hdu-5310-souvenir (c + + && simple math problem)

Source: Internet
Author: User

SouvenirTime limit:2000/1000 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 416 Accepted Submission (s): 270


Problem Descriptiontoday is the 1st anniversary of Bestcoder. Soda, the contest manager, wants to buy a souvenir for each contestant. You can buy the souvenir one by one or set by set in the shop. The price of a souvenir isYuan and the price for a set of souvenirs ifYuan. There ' sSouvenirs in one set.

There ' sContestants in the contest today. Soda wants to know the minimum cost needed to buy a souvenir for each contestant.
Inputthere is multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case:

There ' s a line containing 4 integers.
Outputfor each test case, output of the minimum cost needed.
Sample Input
21 2 2 11 2 3 4

Sample Output
Hintfor 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.

Sourcebestcoder 1st Anniversary ($)
Recommendhujie | We have carefully selected several similar problems for you:5315 5314 5313 5312 5311

Bestcoder Official Analysis:
1001 Souvenir is a simple maths problem. If the package offers, try to buy a suit, or buy a single piece. Note that if you always use a suit, you may not be able to buy it   at the last minute, ie.



#include <iostream> #include <cstdio>using namespace Std;int main () {    int t,n,m,p,q;//unit Price P-element, set Q-Element, A suit with M souvenir, a total of n participants    scanf ("%d", &t);    while (t--)    {        scanf ("%d%d%d%d", &n,&m,&p,&q);        int price = 0;        if (q/m<p)//Assuming the package offer, try        to buy the package {            if ((n%m) *p<q)//Assuming that the final fraction of the purchase package is less expensive than the price per unit                (n/m) *q+ (n%m) * p;//in the last fraction buy unit price            }            else            {prices                = (n/m+1) *q;//otherwise buy a suit            }        }        else//otherwise direct unit price buy        {Price            = n*p;        }        printf ("%d\n", price);    }    return 0;}


Chinese topics in the following:
Souveniraccepts:901submissions:2743Time limit:2000/1000 MS (java/others)Memory limit:262144/262144 K (java/others) problem descriptive narrative
Today is Bestcoder's one-year anniversary. Game Manager Soda wants to prepare a souvenir for each participant. The unit price of souvenirs in the store isCan also be spent at the same timeYuan to buy a souvenir set, in a suitA souvenir. We always have it together today.A participant, soda wants to know at least how much money it takes to prepare a souvenir for everyone.
Input descriptive narrative
Enter more than one set of data. The first line has an integer That represents the number of test data groups. Then for each set of data: A row consists of 4 integers .
Output descriptive narrative
Minimum cost for each set of data output.
Input example
21 2 2 11 2 3 4
Output example
13
Hint
For the first set of data, soda can purchase a package for $1. For the second set of data, soda can buy a souvenir directly for $3.

Hdu-5310-souvenir (c + + &amp;&amp; simple math problem)

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.