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:vector
Method signature:vector thronePosition(int width, int length)
CONSTRAINTS
-width and length will both be between 1 and 5000, inclusive.
EXAMPLES
0)
6
4
Returns: {1, 2 }
This is the example above.
1)
6
5
Returns: {3, 2 }
2)
1
11
Returns: {0, 10 }
3)
12
50
Returns: {5, 6 }
4)
5000
5000
Returns: {2499, 2500 }
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.