TCS Codevita Minimum Distance Solution

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 VAmeters/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.


                                                             Fig:Approaching Intersection
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 non-zero. 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

Sample Input and Output

SNo.InputOutput
1
100
100
10
10

0.0
2
500
300
20
14

41.18252056395
3
100
100
30
40

22.36067977500
5
0
50
-20
30

Invalid Input
Note:

Please do not use package and namespace in your code. For object oriented languages your code should be written in one class.
Note:

Participants submitting solutions in C language should not use functions from as these files do not exist in gcc
Note:

For C and C++, return type of main() function should be int.


Hope this Works For You


#include
#include
int main()
{
    double x,y,vx,vy,z,dnew=0;
    std::cin>>x>>y>>vx>>vy;
    double d=x+y;
while(1)
{
    x=x-vx;
    y=y-vy;
    z=x*x+y*y;
    dnew=sqrt(z);
if(dnew>d)
{
std::cout<

Comments

Popular posts from this blog

A Ten Year Journey: How SEO PowerSuite Has Kept Its SEO Tools Current

4 Ways to Crack a Facebook Password and How to Protect Yourself from Them

Create Separate Contact Page in Blogger