Connection Status:
Competition Arena > Survived
SRM 323 · 2006-10-19 · by Pawa · Geometry, Simple Math
Class Name: Survived
Return Type: double
Method Name: minTime
Arg Types: (int, int, int, int)
Problem Statement

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.

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)
-9
3
2
3
Returns: -1.0

Submissions are judged against all 124 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Survived with a public method double minTime(int x, int y, int V, int U) · 124 test cases · 2 s / 256 MB per case

Submitting as anonymous