Careful Ascent
InterviewTime limit2sMemory limit512 MB
Given a target point and vertical strips that scale horizontal speed, find the launch horizontal velocity so the craft reaches the target at vertical speed 1.
- Level
Medium4 of 10
- Topics
- Math, Implementation, Simulation, Geometry
- Solved
- No attempts yet
Problem
That went well. While police sirens rang out around the palace, Mal Reynolds had already reached the lifting device he had parked outside the city.
No spaceship can leave Planet Zarzos without permission from the High Priest. Mal's spaceship, Firefly, sits in geostationary orbit well above the controlled zone, and his small lifting device is not recognised as an intruder as long as its vertical velocity is exactly 1 km/min.
Two problems remain. First, Mal cannot steer the vehicle from inside his space suit, so he has to set up the autopilot while still on the ground. The vertical velocity must be exactly 1 km/min, and the horizontal velocity must be chosen so that the resulting trajectory hits Firefly. Second, the energy shields of the planet disturb the autopilot. While the device travels through a shield, its horizontal velocity is multiplied by a given factor, and the original horizontal velocity is restored as soon as the device leaves the shield. For this problem Firefly is a single point. The shape drawn in Figure 1 is only decoration.

Figure 1: Illustration of the first example.
Mal recorded the positions of the shields and their influence on the autopilot during his descent. What he needs now is a program that tells him the right horizontal velocity setting.
Input
The input consists of:
- One line with two integers and (, , ), Firefly's coordinates relative to Mal's current position, in kilometres.
- One line with an integer (), the number of shields.
- lines describing the shields. Line contains three numbers:
- an integer (), the lower boundary of shield , in kilometres,
- an integer (), the upper boundary of shield , in kilometres,
- a real value (), the factor the horizontal velocity is multiplied by while the device traverses shield .
Shield ranges do not intersect. For every pair of shields , either or holds.
Every real number has at most 10 digits after the decimal point.
Output
Print, on one line, the horizontal velocity in km/min that Mal must choose in order to reach Firefly.
Round the answer at the tenth digit after the decimal point and always print exactly nine digits after the decimal point. A value that falls exactly halfway rounds away from zero. Print a leading minus sign if the answer is negative.