TopcoderArchive
Archive
Algorithm problem

FireSimulation

Problem statement, definition, constraints, and public examples.

Problem Statement

You have a special model for simulating fire. It is a rectangular grid containing cells of equal size. Each cell contains a digit indicating how many minutes it takes for that cell to burn completely once it catches fire. After a cell is completely burned, the fire spreads to its vertically and horizontally adjacent cells.

You are given a String[] field, where the j-th character of the i-th element is the digit of the cell at row i, column j. At minute 0, the cell at row 0, column 0 catches fire. Return the state of the field at the given minute. The return value must be a String[] formatted exactly like field, but with '*' characters representing cells that are on fire and '.' characters representing cells that have burned completely.

Definition

Class:
FireSimulation
Method:
getState
Parameters:
String[], int
Returns:
String[]
Method signature:
String[] getState(String[] field, int minute)
(be sure your method is public)

Constraints

  • field must contain between 1 and 10 elements, inclusive.
  • Each element of field must contain between 1 and 10 characters, inclusive.
  • Each element of field must contain the same number of characters.
  • field must contain only digits between '1' and '9', inclusive.
  • minute must be between 0 and 100, inclusive.

Examples

  1. {"11111111"}
    4
    Returns: {"....*111" }
  2. {"123456789"}
    5
    Returns: {"..*456789" }
  3. {"111", "211", "311"}
    2
    Returns: {"..*", "**1", "311" }
    At minute 0, it looks like this: {"*11", "211", "311"} At minute 1, the cell at row 0, column 0 is burned completely and the two adjacent cells catch fire: {".*1", "*11", "311"} At minute 2, the cell at row 1, column 0 is still burning (it takes 2 minutes to burn completely). The cell at row 0, column 1 is burned completely and its adjacent cells catch fire. The cell at row 0, column 0 is an adjacent cell, but it's already completely burned, so it's not affected: {"..*", "**1", "311"}
Back to all problems