| ||You are given an N x N board with some 1x1 pieces on it. Each piece is colored and there are at most C colors used. Your task is to move the pieces on the board, so that after those moves each existant color will form one connected group.|
Moves are performed sequentially. Each move consists of choosing one of the pieces and one of the cardinal directions. The piece will move by one cell in that direction and will push other pieces which are in the way in that direction. You cannot move/push any piece outside the board and such moves will be ignored.
First, N and C are randomly chosen, along with P, the probability that a cell contains a piece. If the generated board doesn't require any moves (no pieces, or they are already connected), it is scrapped, and the board generation process repeats (with new values of N, P and C).
The board will be given as an array of strings where each string describes one row of the board and each character is one cell. '0' means an empty cell and a digit X describes a piece of color X. You should return an array of moves, where each move is formatted as "<row> <column> <direction>" where direction is one of the following : NORTH, SOUTH, EAST, WEST.
Your score for an individual test case will be the BEST/YOU. Where YOU is the number of moves returned by your solution and BEST is the lowest number of moves returned by any of the competitors. Any kind of failure (invalid return, exceeding time/memory limit, moves not resulting in connected groups) will result in 0 score for that test. Your total score is simply the sum of scores for every test case.
Score for example tests equals to the number of moves made by your solution.
A visualizer is available for download.
|Method signature:||String getMoves(String board)|
|(be sure your method is public)|
|-||The time limit is 10 seconds and the memory limit is 1024M|
|-||A connected group of one color means that any 2 pieces of the same color should be connected (either directly or indirectly) and the connections are maintained using 4 cardinal directions|
|-||Pieces of different colors may touch each other|
|-||It's possible that even if the C colors were choosen, the genereted board will contain fewer colors|
|-||NORTH describes moves to the lower indexed row, SOUTH to higher to indexed row, WEST to lower indexed column and EAST to higher indexed column|
|-||Moves that are ignored are still counted towards your score|
|-||Rows and columns indexing starts with 0|
|-||There is no code size limit|
|-||Every random variable is chosen with uniform distribution|
|-||P will be between 0.02 and 0.3|
|-||C will be between 1 and 4 (inclusive)|
|-||N will be between 20 and 100|
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.