TopCoder problem "FireSimulation" used in TCHS07 Alpha 2 (Division I Level Three)



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

0)
    
{"11111111"}
4
Returns: {"....*111" }
1)
    
{"123456789"}
5
Returns: {"..*456789" }
2)
    
{"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"}

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10716&pm=7549

Writer:

Mike Mirzayanov

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Simulation