Imperfect GPS
InterviewTime limit2sMemory limit512 MB
Given a running path and a recording interval t, compute the percentage of the real distance the GPS receiver loses by sampling positions at fixed times and joining them with straight lines.
- Level
Medium5 of 10
- Topics
- Geometry, Simulation, Implementation, Math
- Solved
- No attempts yet
Problem
Many runners carry a GPS receiver to count the distance they cover. A receiver is not perfect. It does not record its position continuously. It only saves the position at fixed moments, so it misses parts of the real path. The receiver in this problem works like this.
- It saves the starting position at time 0, when the run begins.
- After that it saves the position every units of time.
- It always saves the position at the final moment of the run, even when the running time is not a multiple of .
The receiver treats the path between two consecutively saved positions as a straight line. Because of that, the distance it computes can come out shorter than the distance really covered.
The left half of the table below is a real path. The runner reached each position at the listed time and stopped running at time 11. If the receiver saves a position every 2 units of time, it records the right half.
The distance really covered is about 14.313708 and the receiver measures about 11.650281. The two differ by about 2.663427, which is about 18.607525% of the real distance.
You are given the positions and times of a running path together with the recording interval of the receiver. Compute what percentage of the real distance the receiver loses. The runner moves in a straight line at constant speed between two consecutive positions.
Input
The input holds a single test case. The first line holds two integers () and (), where is the number of positions on the running path and is the interval at which the receiver saves a position, in seconds.
Each of the next lines holds three integers. On line , the values , () are the coordinates of the -th position on the path, and () is the time in seconds at which the runner reaches it. The values are given in increasing order and no value appears twice. The first position is the start of the run and the last one is the end, so is always 0. The total distance of the run is greater than zero.
Output
Print what percentage of the real distance the receiver loses, rounded to four digits after the decimal point. Print exactly four digits after the decimal point, for example 18.6075 or 0.0000.
The distance the receiver measures never exceeds the real distance, so the answer is never negative. When nothing is lost, print 0.0000 and not a negative zero.