P1909 buy a pencil and p1909 buy a pencil

Source: Internet
Author: User

P1909 buy a pencil and p1909 buy a pencil
Description

Instructor P needs to go to the store to buy n pencils as gifts for children to attend NOIP. She found that there were three kinds of packaging pencils in the store. The number of pencils in different packaging may be different, and the price may be different. To be fair, instructor P decided to buy only the same packaging pencil.

The store does not allow the packaging of pencils. Therefore, teacher P may need to buy more than n pencils to give gifts to friends.

Now, teacher P wants to know how much it will cost to buy at least n pencils * at least * if there is enough packaging in each store.

Input/Output Format

Input Format:

 

The first line contains a positive integer n, indicating the number of pencils required.

In the next three rows, each row describes a packaged pencil with two positive integers: The first integer indicates the number of pencils in the package, and the second integer indicates the price of the package.

Make sure that all 7 values are positive integers up to 10000.

 

Output Format:

 

The output line is an integer, indicating the minimum cost required by instructor P.

 

Input and Output sample input sample #1:
572 250 3030 27
Output sample #1:
54
Input example #2:
9998128 233128 2333128 666
Output sample #2:
18407
Input example #3:
9999101 11111 99991111 9999
Output sample #3:
89991
Description

Three pencil packages are as follows:

• 2-pack, with a price of 2;

• 50-pack, with a price of 30;

• 30-pack, with a price of 27.

Instructor P needs to purchase at least 57 pencils.

If she chooses to buy the first package, she needs to purchase 29 copies, total 2x29 = 58, the cost is 2x29 = 58.

In fact, instructor P will choose the third type of packaging, which requires two copies. Although the number of purchased pencils is more than 30x2 = 60, the cost is reduced to 27x2 = 54, less than the first.

For the second type of packaging, although the price for each pencil is the lowest, you must buy two copies if you want to make enough hair. The actual cost is 30x2 = 60, therefore, instructor P will not select.

So the final output is 54.

Subtask]

The subtask will show the characteristics of some test data. If you encounter difficulties in solving the problem, you can try to solve only a part of the test data.

The data scale and characteristics of each test point are as follows:

The meaning of "integer" in the above table is: if it is "K ", indicates the number of pencils required for the corresponding data. n-it must be an integral multiple of the number of packaging pencils (this means you do not need to buy more pencils ).

 

Pure simulation ..

Question 1

 

 1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 using namespace std; 6 void read(int & n) 7 { 8     char c='+';int x=0; 9     while(c<'0'||c>'9')10     c=getchar();11     while(c>='0'&&c<='9')12     {13         x=x*10+(c-48);14         c=getchar();15     }16     n=x;17 }18 int ans=0x7fffff;19 int main() 20 {21     int n,a,b;22     read(n);23     for(int i=1;i<=3;i++)24     {25         read(a);read(b);26         if(n%a!=0)27         ans=min(ans,(n/a+1)*b);28         else 29         ans=min(ans,(n/a)*b);30     }31     printf("%d",ans);32     return 0;33 }

 

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.