Imagine that a needle in the speedometer, which shows the speed, has fallen off.
It was reattached, but not at the right angle. So, although the speedometer showed the value of the current speed
v
, its actual value wasv+k
, wherek
is an unknown constant (probably also negative). So we started keeping honest records of the trips we made to find out the value of the mysterious constant k.Input:
The first line of the input contains two integers:
n
(1 ≤ n ≤ 1000), which represents the number of parts of a single run, andt
(1 ≤ t ≤ 10^6), which represents the total run time.This is followed by
n
lines, where each describes one part of the trip that we recorded. Each line contains two integers:s
(1 ≤ s ≤ 1000) andv
(|v| ≤ 1000), the distance and speed indicated by the speedometer with the needle stuck on during that part of the journey. Keep in mind that even though the speedometer needle on the glove box may have negative readings, its actual speed was always greater than 0 during every part of the trip. The time is given in hours, the distance in kilometres and the speed in kilometres per hour.Output:
The problem is to find K. The mysterious constant k given in kilometers per hour.
Example of Input:
3 5 4 -1 4 0 10 3
Output:
3.000000000
Input:
4 10 5 3 2 2 3 6 3 1
Output:
-0.508653377
Well, I was told that this problem can be solved with Approximate algorithm.
Can someone write a pseudocode solution or explain how exactly I can solve this problem with this algorithm?