Problem : 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.

**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

**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

**Constraints:**

x > 0

y > 0

VA > 0

VB > 0

Calculation and printing of output should be done upto 11 precision

**Input 1**

100

100

10

10

**Output 1**

**0.0**

**Input 2**

500

300

20

14

**Output 2**

41.18252056395

**Input 3**

100

100

30

40

**Output 3**

22.36067977500

Input 4

Input 4

05

0

20

30

**Output 4**

Invalid Input

TCS CodeVita 2018 Round1 Question: Consecutive Prime Sum

C-Language Program (MockVita1/Problem C)

#include <stdio.h>

#include <math.h>

int main(void) {

int x,y,va,vb;

double min;

double d;

scanf("%d %d %d %d",&x,&y,&va,&vb);

if(x<0 || y<0 || va<0 || vb<0)

printf("Invalid Input");

else

{

min = sqrt(x*x + y*y);

while(x>=0 || y>=0)

{

x-=va;

y-=vb;

d=sqrt(x*x + y*y);

if(d<min)

min = d;

}

if(min==0.0)

printf("0.0");

else

printf("%.11lf",min);

}

return 0;

}

Source:

https://www.google.in/

* Ask us, what you want?

EmoticonEmoticon