Refract Facts
Time limit1sMemory limit256 MB
Given the submarine depth, jet height, horizontal distance and refraction indices, compute the laser elevation angle that hits the jet after refraction.
- Level
Medium5 of 10
- Topics
- Binary search, Math
- Solved
- No attempts yet
Problem

A submarine sends a message to a jet cruising overhead with a communications laser. The sea surface is flat. The submarine cruises at depth below the surface. The jet is at height above the surface and at horizontal distance from the submarine. The submarine already turned toward the jet before starting communications, so the only thing left to settle is the angle of elevation at which to aim the laser.
When the laser passes from the sea into the air it is refracted, so its path bends. Snell's law describes the refraction. Light that reaches the flat surface at angle from the vertical leaves at angle from the vertical, and the two angles satisfy

is measured in the water and in the air, both from the vertical, and and are the refraction indices of the water and the air. The refraction index of a material is inversely proportional to how fast light travels through that material.
The angle of elevation is measured from the horizontal at the submarine.
Input
The input consists of one or more datasets.
Each dataset is one line with five floating point numbers, in this order:
- , the depth of the submarine (of the laser emitter, to be exact) in feet,
- , the height of the jet in feet,
- , the horizontal distance from the submarine to the jet in feet,
- , the refraction index of the water,
- , the refraction index of the air,
A line whose is 0 ends the input. All five numbers on that line are 0 and the line is not a dataset.
Output
For each dataset, print one line with the angle of elevation in degrees at which the submarine should aim its laser to illuminate the jet. Round the angle to the closest 1/100 of a degree and print exactly two digits after the decimal point.