P1968 USD and p1968 USD

Source: Internet
Author: User

P1968 USD and p1968 USD
Background

Maxint + 1 count is omitted here

Description

In the next few days, David will learn the exchange rate between the dollar and the German mark. Programming helps David decide when to buy or sell mark or dollar so that he can get the highest possible value starting from $100.

Input/Output Format Input Format:

The first line of the input file is a natural number N, 1 ≤ N ≤ 100, indicating the number of days David learned the exchange rate.

In the next N rows, each row is A natural number A, 1 ≤ A ≤ 1000. A In line I + 1 indicates the average exchange rate on the day I + 1 that we know in advance. On this day, david can buy both $100 for Mark A and $100 for Mark.

Output Format:

The first row of the output file is also the only row of the expected amount of money (in USD, retain two decimal places ).

Note: Considering the bitwise error in the real number arithmetic operation, the result within the correct result range of $0.05 is considered correct. David must replace his money with the dollar before the end of the last day.

Input and Output sample Input example #1:
5400300500300250
Output sample #1:
266.66
Description

Example (no output required)

Day 1... changing $100.0000 = 400.0000 mark

Day 2... changing 400.0000 mark = $133.3333

Day 3... changing $133.3333 = 666.6666 mark

Day 5... changing 666.6666 mark = $266.6666

 

Let's talk about my ideas:

First, we can launch:

Dollar-to-mark ratio: [(owned USD) * mark of the Day]/100

The ratio of the mark to the dollar is: (100 * with the dollar)/the mark of the day

Then we can find that when the mark on day I is more than the mark on day I + 1, we cannot use the mark for the dollar.

Because the dollar for the day I + 1 must be more than the day I

Then initialize it, And the AC will be involved.

Although the Code is longer than all the questions .....

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 using namespace std; 6 void read (int & n) 7 {8 char c = '+'; int x = 0; bool flag = 0; 9 while (c <'0' | c> '9 ') 10 {11 c = getchar (); 12 if (c = '-') flag = 1; 13} 14 while (c> = '0' & c <= '9') 15 x = x * 10 + c-48, c = getchar (); 16 flag = 1? N =-x: n = x; 17 18} 19 const int MAXN = 101; 20 int n; 21 double dp [MAXN] [3]; // dp [I] [0] indicates the number of marks 22 on the day I/dp [I] [1] indicates the amount of USD 23 on the day I, double mark [MAXN]; 24 int main () 25 {26 read (n); 27 for (int I = 1; I <= n; I ++) 28 // read (mark [I]); 29 cin> mark [I]; 30 for (int I = 1; I <= n; I ++) 31 {32 dp [I] [0] = max (mark [I], dp [I-1] [0]); 33 dp [I] [1] = max (100.00, dp [I-1] [1]); // initial status 34 dp [I] [1] = max (dp [I] [1], (dp [I] [0] * 100)/mark [I]); // replace mark with US $35 dp [I] [0] = max (dp [I] [0], (dp [I] [1] * mark [I])/100); 36 if (I! = N & mark [I + 1] <mark [I]) continue; 37 dp [I] [0] = max (dp [I] [0], (double) dp [I] [0]/mark [I] * mark [I]); 38 dp [I] [1] = max (dp [I] [1], (dp [I] [0] * 100)/mark [I]); // replace mark with USD 39} 40 double maxn = 0; 41 for (int I = 1; I <= n; I ++) 42 {43 maxn = max (100.00 * dp [I] [0])/mark [I], maxn ); 44 maxn = max (maxn, dp [I] [1]); 45} 46 printf ("%. 2lf ", maxn); 47 return 0; 48}

 

Related Article

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.