TopCoder problem "TwoKings" used in SRM 243 (Division I Level Three)



Problem Statement

    A white queen and two black kings are placed on a 100 x 100 chessboard. White and black sides move by turns. The white queen moves first (only one of the two black kings is moved on each turn). Given three Strings, queen, king1 and king2, return the minimal number of white moves needed to capture one of the kings (kings are not allowed to capture the queen, and may not move to the queen's location). queen, king1 and king2 will each contain the 0-based row and column of the corresponding piece.
 

Definition

    
Class:TwoKings
Method:captureKing
Parameters:String, String, String
Returns:int
Method signature:int captureKing(String queen, String king1, String king2)
(be sure your method is public)
    
 

Notes

-The black side tries to avoid capturing as long as possible.
-Kings move one cell in any direction, horizontally, vertically, or diagonally.
-The queen moves any number of cells in any direction, horizontally, vertically, or diagonally.
-The queen captures a king if it moves to the cell that the king occupies.
-Neither side can skip a turn.
-Pieces may not move off the board.
 

Constraints

-queen, king1 and king2 will each contain two space-delimited integers between 0 and 99, inclusive.
-The numbers in queen, king1 and king2 will not contain leading zeroes.
-No two pieces will occupy the same cell.
 

Examples

0)
    
"0 0"
"99 0"
"0 99"
Returns: 1
You can capture any king on the first turn.
1)
    
"98 98"
"0 97"
"99 0"
Returns: 2
You can move to the "0 0" cell and threaten both kings. You will capture one of them on the next turn.
2)
    
"16 35"
"53 36"
"23 40"
Returns: 3
3)
    
"22 53"
"95 64"
"30 76"
Returns: 4

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=7218&pm=4582

Writer:

Olexiy

Testers:

PabloGilberto , lbackstrom , brett1479

Problem categories:

Simulation