TopCoder problem "SpiralRoute" used in SRM 371 (Division I Level One , Division II Level Two)



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

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 }

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10787&pm=8262

Writer:

bmerry

Testers:

PabloGilberto , Yarin , ivan_metelsky

Problem categories:

Simple Math