Array ( [0] => [1] => questions [2] => Strings [3] => Minimum-Distance )
Two riders A and B are travelling on a highway towards each other on two roads that intersect at right angle at speeds VA meters/second and VB meters/second. A is at a distance of 'x' meters and B is at a distance of 'y' meters from the intersection. Calculate the minimum distance between these two riders that is possible.
First line contains the distance of Rider A from intersection denoted by x
Second line contains the distance of Rider B from intersection denoted by y
Third line contains the Velocity of Rider A denoted by VA
Fourth line contains the Velocity of Rider B denoted by VB
Constraints:
x > 0
y > 0
VA > 0
VB > 0
Calculation and printing of output should be done upto 11 precision
Print the minimum distance between these two riders, if minimum distance is nonzero. If minimum distance is zero, print it as 0.0
100 100 10 10
0
500 300 20 14
41.18252056395
100 100 30 40
22.36067977500
Login to see Discussion
here we are using the pythagoras theorem. As in question it is mentioned that roads are at right angle their distance can be calcualted using pythagoras formula
which is sqaure root of sum of other two squares
So, first we calculate the initial distance between two bikes as time passes we reduce their each distance by velocity given as they approach closer by the given velocity.
Every time we calculate the distance and update the minimum till any one the distance is greater than 0
Finally we print the result
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution