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 and width . Where , there is sea. Where and , there is sand. The rest is covered by grass. You are at a position strictly inside the beach. Walking a unit on the sand causes pain . Walking a unit on the grass causes pain , with .
To the right we see an example with , and . The black dot shows the origin . The red dot shows your position. If and , the best path (in blue) goes straight into the sea. If and , the best path (in pink) goes first straight on the sand to the point , 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) (47,85)(20,85) (53,85)(80,85)
(85,50) (85,47)(85,20) (85,53)(85,80)
Given , , , , and , can you minimize the pain to reach the sea?
Input consists of several cases, each with , , , , and . They are strictly positive real numbers with at most three digits after the decimal point. Assume , , and .
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.
Author: Salvador Roura
Generation: 2026-01-25T12:06:50.831Z
© Jutge.org, 2006–2026.
https://jutge.org