Problem Statement
In the game of Rendezvous, two pieces move on a two-dimensional grid. Both pieces are restricted to integer coordinates. The target piece begins at coordinates (x,y), and the seeker piece begins at coordinates (0,0). On every turn the target piece moves dx units horizontally and dy units vertically. Similarly, the seeker piece moves DX units horizontally and DY units vertically on every turn. For example, at the end of the first turn, the target piece is at coordinates (x+dx,y+dy) and the seeker piece is at coordinates (0+DX,0+DY). The values of dx, dy, DX, and DY are limited to integers between -1000 and 1000, inclusive.
You control the movement of the seeker piece. In other words, you choose the values of DX and DY. Your goal is to make the seeker piece rendezvous with the target piece in the minimum number of turns. A rendezvous occurs when both pieces end a turn at the same coordinates.
Create a class Rendezvous with a method interceptVector
that takes
Definition
- Class:
- Rendezvous
- Method:
- interceptVector
- Parameters:
- int, int, int, int
- Returns:
- int[]
- Method signature:
- int[] interceptVector(int x, int y, int dx, int dy)
- (be sure your method is public)
Notes
- Given the input constraints, if the seeker cannot catch the target within 10000 turns, it will never catch the target.
Constraints
- x and y are between -10000 and 10000, inclusive, but are not both 0.
- dx and dy are between -1000 and 1000, inclusive.
Examples
500
300
55
33
Returns: { 555, 333 }
Pieces meet at the end of the first turn.
500
300
600
700
Returns: { 850, 850 }
Pieces meet at the end of the second turn.
1
1
1000
1000
Returns: { }
The seeker piece can never catch the target piece.
9519
-1002
857
-534
Returns: { 914, -540 }
-1024
333
15
-186
Returns: { }
0
3988
500
0
Returns: { 500, 997 }
1000
1001
0
0
Returns: { }
10000
-10000
999
-999
Returns: { 1000, -1000 }
1011
337
-3
902
Returns: { 0, 903 }
2000
1000
-999
-999
Returns: { 1, -499 }
1
2
3
4
Returns: { 4, 6 }
79
-80
-79
80
Returns: { 0, 0 }
-2343
978
1
126
Returns: { -780, 452 }
9999
-9997
997
-999
Returns: { }
3145
5926
535
879
Returns: { }
9967
0
-4
-567
Returns: { -3, -567 }
555
3441
986
-46
Returns: { 991, -15 }
-500
-400
-1000
-1000
Returns: { }
78
1078
15
-1000
Returns: { 93, 78 }
983
977
16
-4
Returns: { 999, 973 }
0
1
1
0
Returns: { 1, 1 }
10000
10000
1
1
Returns: { 626, 626 }
10000
10000
999
999
Returns: { 1000, 1000 }
9519
-1002
857
-534
Returns: { 914, -540 }
1001
1001
-1
-1
Returns: { 1000, 1000 }
-2001
-2001
1
1
Returns: { -666, -666 }
0
1
0
0
Returns: { 0, 1 }
500
500
500
500
Returns: { 1000, 1000 }
0
10000
0
0
Returns: { 0, 1000 }
10000
10000
1000
1000
Returns: { }
-1000
-1000
-5
-5
Returns: { -505, -505 }
1001
5001
-3
-3
Returns: { }
10000
10000
1
999
Returns: { 2, 1000 }
0
5
0
0
Returns: { 0, 5 }
1
10
999
1000
Returns: { }
0
1000
0
500
Returns: { 0, 1000 }
2477
2477
-1
-1
Returns: { 0, 0 }