Java
Programming and Technical
HR Interview
Interview
function of array
Read Solution (Total 0)
Java Other Question
how to replace , in a given string without using predefined methods
Circles and Distances
Problem Description
Task is to calculate the straight line distance between the two objects moving in a circular path. They may move at different velocities. The distance has to be calculated after N seconds.
The figure and commentary below it, explains the problem in detail.
com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@491cde5b:image1.png
We have two point objects B and C at rest on a straight line at a distance r1 and r2 units from a point A. At time t=0 seconds, the objects start moving in a circular path with A at the center with velocity v1 and v2 degrees per second.
Given inputs v1, v2, r1 and r2, calculate the distance between the B and C after N seconds.
Distance should be printed up to an accuracy of 2 places after the decimal point. Use Rounding Half-up semantics.
Input Format
First line contains velocity of object B in degrees per second (v1)
Second line contains distance of object B from A (r1)
Third line contains velocity of object C in degrees per second (v2)
Fourth line contains distance of object C from A (r2)
Fifth line contains time in seconds after which the distance between B and C, is to be measured (N)
Output
The distance between B and C, N seconds after they are set in motion
Constraints
v1, v2, r1, r2 > 0 and all are integer values.
r2 > r1
0 < n <= 100
The objects move in anticlockwise direction
v1, v2 <=360
r2 <= 100
Explanation
Example 1
Input
90
5
270
10
1
Output
15.00
Explanation
After 1 second, the object at B would cover 90 degrees and the object at C would cover 270 degrees. Both the objects would be vertically opposite to each other and would lie in a straight line.
So the distance between them would be equal to the sum of their distance from the origin A=5+10= 15