JOIN
Get Time

   Problem Statement  

 Problem Statement for CoinsGameEasy

Problem Statement

    We are playing a game with a pair of coins on a rectangular board. The board is divided into unit square cells. Each cell is either empty, or it contains an obstacle. The board is given to you as a String[] board. The character '#' represents an obstacle, '.' is an empty cell, and 'o' is an empty cell with a coin. You may assume that there are exactly two coins on the board, and that initially they lie in different cells.





Next to the board, there are 4 buttons labeled "Left", "Right", "Up", and "Down". The game is played by pushing these buttons. When you push a button, all coins will try to move one cell in the corresponding direction. For each coin, there can be three different outcomes:
  • If the next cell in the chosen direction contains an obstacle, the coin remains in its current cell.
  • If there is no next cell in the chosen direction (i.e., if the coin is already on the corresponding edge of the board), the coin falls off the board.
  • In all other cases, the coin moves one cell in the chosen direction. Note that this includes the case when the destination cell currently contains another coin.






The goal of the game is to make exactly one coin fall off the board. If that is impossible, or if you need to push more than 10 buttons in order to achieve the goal, return -1. Otherwise, return the smallest number of times you need to push a button in order to achieve the goal.
 

Definition

    
Class:CoinsGameEasy
Method:minimalSteps
Parameters:String[]
Returns:int
Method signature:int minimalSteps(String[] board)
(be sure your method is public)
    
 

Notes

-There may be some sequences of moves that will cause both coins to end in the same cell. Note that when trying to win the game such moves should be avoided.
 

Constraints

-board will contain between 1 and 20 elements, inclusive.
-Every element of board will have the same length, and this length will be between 1 and 20, inclusive.
-Each character in each element of board will be one of '#', 'o' and '.'.
-There will be exactly 2 'o' in board.
 

Examples

0)
    
{"oo"}
Returns: 1
Push the Left button. The left coin will fall, the right one will move one step left and it will still be on the board.
1)
    
{".#", 
 ".#", 
 ".#",
 "o#",
 "o#",
 "##"}
Returns: 4
You need to push the Up button 4 times in a row.
2)
    
{"..",
 "..",
 "..",
 "o#",
 "o#",
 "##"}
Returns: 3
As in Example 1, this game can be won by pushing the Up button 4 times. However, there is also a shorter solution: push Up, Right, and Right, in this order.
3)
    
{"###",
 ".o.",
 "###",
 ".o.",
 "###"}
Returns: -1
4)
    
{"###",
 ".o.",
 "#.#",
 ".o.",
 "###"}
Returns: 3
5)
    
{"###########",
 "........#o#",
 "###########",
 ".........o#",
 "###########"}
Returns: 10
6)
    
{"############",
 ".........#o#",
 "############",
 "..........o#",
 "############"}
Returns: -1
You need at least 11 steps to win the game, so you should return -1.

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.

This problem was used for:
       Single Round Match 563 Round 1 - Division II, Level Two