TopCoder problem "Survived" used in SRM 323 (Division I Level Two)



Problem Statement

    You have survived a shipwreck and need to swim to the land. You can swim at a speed of at most V meters per second. The ocean's stream moves you with a constant speed of U meters per second.

Imagine a Cartesian system of coordinates in which you are at point (0,0), and the ocean's stream moves in the positive direction of the x-axis. You are given four integers x, y, V and U. Return a double representing the minimum time in seconds in which you can reach point (x, y). If this point can't be reached, return -1.
 

Definition

    
Class:Survived
Method:minTime
Parameters:int, int, int, int
Returns:double
Method signature:double minTime(int x, int y, int V, int U)
(be sure your method is public)
    
 

Notes

-Your return value must have an absolute or relative error less than 1e-9.
 

Constraints

-x and y will be between -100 and 100, inclusive.
-U and V will be between 0 and 100, inclusive.
 

Examples

0)
    
1
-1
1
1
Returns: 1.0
If you swim directly down (in the negative direction of the y-axis) for one second, you will have gone forward one meter. By that time, the ocean's stream will have taken you one meter in the positive direction of the x-axis, leaving you at point (1, -1).
1)
    
1
1
1
0
Returns: 1.4142135623730951
2)
    
1
1
0
1
Returns: -1.0
3)
    
9
3
2
3
Returns: 2.0593413823019864
4)
    
0
0
0
0
Returns: 0.0
5)
    
5
12
24
26
Returns: 1.3

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6782

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10003&pm=6782

Writer:

Pawa

Testers:

PabloGilberto , brett1479 , Olexiy , lovro

Problem categories:

Geometry, Simple Math