TopcoderArchive
TCO1 Aug 2019
TCO19 Japan Fun Round

RealWithRooks

Problem statement, definition, constraints, and public examples.

Problem Statement

You have an empty R x C chessboard and N colorless rooks. You are going to paint each rook either white or black. Then, you are going to place each rook onto some empty square of the chessboard. Your goal is to create a configuration that maximizes the number of attacking pairs of rooks.

Recall that two rooks attack each other if:

  • They have opposite colors.
  • They are in the same row or in the same column.
  • In that row or column, all squares that are between the two rooks are empty.

Return a String[] describing any one optimal placement of the rooks. The returned String[] must have R elements, each of those must have C characters, and each of those must be '.' (empty square), 'W' (white rook) or 'B' (black rook).

Definition

Class:
RealWithRooks
Method:
construct
Parameters:
int, int, int
Returns:
String[]
Method signature:
String[] construct(int R, int C, int N)
(be sure your method is public)

Constraints

  • R will be between 1 and 50, inclusive.
  • C will be between 1 and 50, inclusive.
  • N will be between 1 and R*C, inclusive.

Examples

  1. 2
    4
    8
    Returns: {"WBWB", "BWBW" }
    In this test case you need to fill the whole board. There are still many ways to do so. You need to choose the colors in a way that maximizes the number of attacking pairs.
  2. 5
    5
    9
    Returns: {"W.B.W", ".....", "B.W.B", ".....", "W.B.W" }
  3. 4
    7
    3
    Returns: {".......", ".W...BW", ".......", "......." }
  4. 5
    6
    27
    Returns: {"..WBWB", ".WBWBW", "WBWBWB", "BWBWBW", "WBWBWB" }
Back to all problems