On the beach P94819


Statement
 

pdf   zip

You have been sunbathing on a sand beach, and now you want to take a bath. You touch the sand, but it burns! How can you minimize the total pain to reach the sea?

0.53 Assume a two-dimensional world. The beach has length \ell and width ww. Where y0y \le 0, there is sea. Where 0<x<0 < x < \ell and 0<y<w0 < y < w, there is sand. The rest is covered by grass. You are at a position (a,b)(a, b) strictly inside the beach. Walking a unit on the sand causes pain ss. Walking a unit on the grass causes pain gg, with g<sg < s.

To the right we see an example with =w=30\ell = w = 30, a=12a = 12 and b=20b = 20. The black dot shows the origin (0,0)(0, 0). The red dot shows your position. If s=3s = 3 and g=2g = 2, the best path (in blue) goes straight into the sea. If s=13s = 13 and g=5g = 5, the best path (in pink) goes first straight on the sand to the point (0,15)(0, 15), and then straight on the grass into the sea.

0.50

(100,100)

(20,20)(20,80)(80,80)(80,20)

(00,20)(20,20)(20,80)(80,80)(80,20)(100,20)(100,100)(0,100)(00,20)

(00,00)(00,20)(100,20)(100,00)(00,00)

(19.5,20)2

(44,60)(19.5,40) (19.5,40)(19.5,20)

(44,60)(44,20)

(44,60)2

(50,85)\ell (47,85)(20,85) (53,85)(80,85)

(85,50)ww (85,47)(85,20) (85,53)(85,80)

Given \ell, ww, aa, bb, ss and gg, can you minimize the pain to reach the sea?

Input

Input consists of several cases, each with \ell, ww, aa, bb, ss and gg. They are strictly positive real numbers with at most three digits after the decimal point. Assume a<a < \ell, b<wb < w, and g<sg < s.

Output

For every case, print the minimum total pain to reach the sea with three digits after the decimal point. The input cases have no precision issues.

Public test cases
  • Input

    30 30 12 20 3 2
    30 30 12 20 13 5
    25.5 12.1 23.6 4.7 18.4 5.3
    

    Output

    60.000
    244.000
    58.388
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++