Array ( [0] => [1] => questions [2] => Basic [3] => Minimum-Distance ) Codevita Previous Questions | Minimum Distance | THE INQUISITIVE " /> ">





Minimum Distance

LEVEL:Beginner

Description

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.

Input Format

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

Output Format

Print the minimum distance between these two riders, if minimum distance is nonzero. If minimum distance is zero, print it as 0.0


Example 1:

Input
100
100
10
10
Output
0
Example 2:

Input
500
300
20
14
Output
41.18252056395
Example 3:

Input
100
100
30
40
Output
22.36067977500

oops

Login to see Discussion




Approach

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.

oops

Login to see Solution