"The best plan for buying books"

Source: Internet
Author: User

"The best plan for buying books"

Problem Description: The number of different five books to buy, one buy a copy of 8 yuan, buy two books with different numbers enjoy 5% discount, different numbers three book enjoy 10% discount, different numbered four book enjoy 20% discount, different numbered five book enjoy 25% discount, Pay attention to buy the same number of books do not enjoy discounts, according to the amount of books provided by customers, to design the best purchase plan for customers to buy the desired quantity at the lowest price.

Design ideas: Through the purchase of 10 books within the scheme design, the rule of the best plan is that in addition to buy 8 is the exception, the rest of the best plan is to buy a full set of books, plus the purchase of a separate buy book quantity of the whole book after the remainder combination can be obtained.

Source:

//achieve the best solution to purchase the book//Li min, May 10th,2015#include <iostream>using namespacestd;voidMain () {intb; Doublec,d,e; cout<<"Please enter the number of books you need to buy:"<<Endl; CIN>>A; if(a%5==0) {b=0; }    if(a%5==1) {b=1; }    if(a%5==2) {b=2; }    if(a%5==3) {b=3; }    if(a%5==4) {b=4; }    Switch(b) { Case 0:d =5*8*0.75; if(a==5) {cout<<"the best purchase plan is five books each buy 1 copies"<<Endl; cout<<"the"<<Endl; cout<<"The minimum price to be paid is:"<<d<<"Yuan"; }        Else{cout<<"the best purchase proposal is to buy"<<a/5<<"set of book"<<Endl; cout<<"the"<<Endl; cout<<"The minimum price to be paid is:"<<a/5*d<<"Yuan"; }         Break;  Case 1: d=5*8*0.75; E=8.0; if(a==1) {cout<<"the best book proposal is a five-volume book to buy one of them can"<<Endl; cout<<"the"<<Endl; cout<<"The minimum price to be paid is:"<<e<<"Yuan"; }        Else{cout<<"the best purchase proposal is to buy"<< (A-1)/5<<"book and buy one of five volumes"<<Endl; cout<<"the"<<Endl; cout<<"The minimum price to be paid is:"<<e+ (A-1)/5*d<<"Yuan"; }         Break;  Case 2:d =5*8*0.75; E= -*0.95; if(a==2) {cout<<"the best book option is to buy two different books in five volumes"<<Endl; cout<<"the"<<Endl; cout<<"The minimum price to be paid is:"<<e<<"Yuan"; }        Else{cout<<"the best purchase proposal is to buy"<< (A-2)/5<<"set of books, and then buy five volumes of the book Two of them can be"<<Endl; cout<<"the"<<Endl; cout<<"The minimum price to be paid is:"<<e+ (A-2)/5*d<<"Yuan"; }         Break;  Case 3:d =5*8*0.75; E= -*0.9; C=4*8*0.8*2; if(a==3) {cout<<"the best book proposal is to pick three different books to buy."<<Endl; cout<<"the"<<Endl; cout<<"The minimum price to be paid is:"<<e<<"Yuan"; }        Else if(a==8) {cout<<"the best purchase plan is to choose four different books to buy two sets of the book can be"<<Endl; cout<<"the"<<Endl; cout<<"The minimum price to be paid is:"<<c<<"Yuan"; }        Else{cout<<"the best purchase proposal is to buy"<< (A-8)/5<<"set the book, and then choose four different books two sets of purchase can be"<<Endl; cout<<"the"<<Endl; cout<<"The minimum price to be paid is:"<<c+ (A-8)/5*d<<"Yuan"; }         Break;  Case 4:d =5*8*0.75; E= +*0.8; if(a==4) {cout<<"the best book proposal is to pick four different books to buy."<<Endl; cout<<"the"<<Endl; cout<<"The minimum price to be paid is:"<<e<<"Yuan"; }        Else{cout<<"the best purchase proposal is to buy"<< (A-4)/5<<"set of books, and then buy five volumes of the book four of them can be"<<Endl; cout<<"the"<<Endl; cout<<"The minimum price to be paid is:"<<e+ (A-4)/5*d<<"Yuan"; }         Break; }}

Experimental results:

Programming Summary: This is a very simple mathematical problem, first of all to know what to solve the problem, that is, what the final result is, and secondly, the problem should be refined, not too much trouble, to believe that eventually will find certain rules. Many times in solving problems, do not be too impatient, you should calm down to think carefully, or will complicate the problem and finally solve the problem. There are more on the machine practice, more practice, more accumulation, more looking, more search, more questions, more thinking and more tests, and finally I believe that their ability will be improved!

"The best plan for buying books"

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.