Problem:
-
Total time limit:
-
1000ms
-
Memory Limit:
-
65536kB
-
-
Describe
-
-
An online bookstore to hold preferential promotion, there are two kinds of preferential strategies. Strategy one is the total purchase of more than 100 yuan can enjoy free shipping. Strategy Two is that if the number of books is more than 3, then the total purchase of books to enjoy 95 percent discount (excluding freight). Two preferential strategies can not be enjoyed at the same time, up to one of the preferential strategies. The shipping cost is 20 yuan. Xiao Ming wants to buy books on this website, please help him choose the best preferential strategy.
-
-
Input
-
-
There are many lines, the first line is to buy the kind of book n (0 <= N <= 100), the next n rows each line enters a bibliography of the purchase quantity m and the cost P (p is not necessarily an integer). When n is-1 o'clock end input
-
-
Output
-
-
for each group of data, analyze how to enjoy the preferential strategy, output the minimum amount of purchase book payment
-
-
Sample input
-
-
22 603 50-1
-
-
Sample output
-
-
270
Solution:
#include<iostream>using namespaceStd;int Main(){intN; while(Cin>>N){if(N==-1){ Break;}DoubleA[N],B[N]; for(intI=0;I<N;I++){Cin>>A[I]>>B[I];}intAll=0;DoubleAllmoney=0;DoubleCost1=0;DoubleCost2=0; for(intI=0;I<N;I++){All+=A[I];Allmoney+=A[I]*B[I];}Cost1=Allmoney;Cost2=Allmoney;if(All>3){Cost1*=0.95;Cost1+= -;}Else{Cost1+= -;}if(Allmoney> -){}Else{Cost2+= -;}if(Cost1<Cost2){cout<<Cost1<<Endl;}Else{cout<<Cost2<<Endl;}}return 0; }
Openjudge solution (c + +)--title 4040: Buying book questions