Problem Statement
The King of Elbonia lives in a palace that is width meters by length meters. Since he makes his subjects live in mud, he is not very popular. He wants the palace partitioned so that visitors have to walk a long way to reach him. His security advisors have settled on a spiral. A visitor enters the palace at the South-West corner and starts walking East. Every time the visitor reaches an outer wall or his own path, he turns left. The corridors in the spiral are 1 meter wide. The diagram below shows an example of a spiral path: the visitor moves from a (the South-West corner) through the alphabet to x, the throne.
nmlkji oxwvuh pqrstg abcdef
The King wants to have his throne correctly placed before all the partitioning is done, so he needs to know where the spiral will end. Write a class SpiralRoute with a method thronePosition that returns two integers, indicating the coordinates of the throne. The South-West corner is (0, 0), the South-East corner is (width - 1, 0) and the North-East corner is (width - 1, length - 1).
Definition
- Class:
- SpiralRoute
- Method:
- thronePosition
- Parameters:
- int, int
- Returns:
- int[]
- Method signature:
- int[] thronePosition(int width, int length)
- (be sure your method is public)
Constraints
- width and length will both be between 1 and 5000, inclusive.
Examples
6
4
Returns: {1, 2 }
This is the example above.
6
5
Returns: {3, 2 }
1
11
Returns: {0, 10 }
12
50
Returns: {5, 6 }
50
50
Returns: {24, 25 }
1
1
Returns: {0, 0 }
1
2
Returns: {0, 1 }
1
3
Returns: {0, 2 }
1
4
Returns: {0, 3 }
4
1
Returns: {3, 0 }
3
1
Returns: {2, 0 }
2
1
Returns: {1, 0 }
1
1
Returns: {0, 0 }
2
2
Returns: {0, 1 }
3
3
Returns: {1, 1 }
4
4
Returns: {1, 2 }
5
5
Returns: {2, 2 }
48
48
Returns: {23, 24 }
49
49
Returns: {24, 24 }
50
50
Returns: {24, 25 }
40
35
Returns: {22, 17 }
40
36
Returns: {17, 18 }
40
38
Returns: {18, 19 }
40
41
Returns: {19, 20 }
40
42
Returns: {19, 20 }
40
43
Returns: {19, 20 }
40
44
Returns: {19, 20 }
45
1
Returns: {44, 0 }
45
10
Returns: {4, 5 }
45
43
Returns: {23, 21 }
45
44
Returns: {21, 22 }
45
46
Returns: {22, 23 }
45
47
Returns: {22, 24 }
45
50
Returns: {22, 27 }
35
40
Returns: {17, 22 }
36
40
Returns: {17, 18 }
38
40
Returns: {18, 19 }
41
40
Returns: {19, 20 }
42
40
Returns: {19, 20 }
43
40
Returns: {19, 20 }
44
40
Returns: {19, 20 }
1
45
Returns: {0, 44 }
10
45
Returns: {4, 5 }
43
45
Returns: {21, 23 }
44
45
Returns: {21, 22 }
46
45
Returns: {23, 22 }
47
45
Returns: {24, 22 }
50
45
Returns: {27, 22 }
2
10
Returns: {0, 1 }
10
2
Returns: {0, 1 }
2
11
Returns: {0, 1 }
11
2
Returns: {0, 1 }
5000
5000
Returns: {2499, 2500 }
5000
4999
Returns: {2500, 2499 }
4999
5000
Returns: {2499, 2500 }
4998
5000
Returns: {2498, 2499 }
5000
4998
Returns: {2498, 2499 }
4999
4997
Returns: {2500, 2498 }
4999
4999
Returns: {2499, 2499 }
4997
4999
Returns: {2498, 2500 }
1
5000
Returns: {0, 4999 }
5000
1
Returns: {4999, 0 }
5000
2
Returns: {0, 1 }
2
5000
Returns: {0, 1 }
4096
2048
Returns: {1023, 1024 }
4095
2047
Returns: {3071, 1023 }
2003
4999
Returns: {1001, 3997 }
4954
4999
Returns: {2476, 2477 }
3
99
Returns: {1, 97 }
4999
4899
Returns: {2549, 2449 }
1353
4629
Returns: {676, 3952 }
2
3
Returns: {0, 1 }
3
5
Returns: {1, 3 }
4901
2283
Returns: {3759, 1141 }
3
2
Returns: {0, 1 }
3
5000
Returns: {1, 4998 }
2
20
Returns: {0, 1 }
2
5
Returns: {0, 1 }
15
1
Returns: {14, 0 }
359
4888
Returns: {179, 4708 }
10
1
Returns: {9, 0 }