WAGE - Wood, Axe and Grass
Danny has created a new civilization on a 2D grid. At the outset each grid location may be occupied by one of three life forms: Woods, Axe, or Grass. Each day, differing life forms occupying horizontally or vertically adjacent grid locations wage war. In each war, Woods always defeat Axe, Axe always defeat Grass, and Grass always defeat Woods. At the end of the day, the winner expands its territory to include the loser's grid position. The loser vacates the position. Determine the territory occupied by each life form after n days.
Input
The first line of input contains t, the number of test cases. Each test case begins with three integers not greater than 100: r and c, the number of rows and columns in the grid, and n. The grid is represented by the r lines that follow, each with c characters. Each character in the grid is W, A, or G, indicating that it is occupied by Woods, Axe, or Grass respectively.
Output
For each test case, print the grid as it appears at the end of the nth day.
Example
Input: 2 3 3 1 WWW WAW WWW 3 4 2 WAGW AGWA GWAG Output: WWW WWW WWW WWWA WWAG WAGW
hide comments
Aamir Khan:
2011-10-01 19:39:28
What would be the answer in case
|
|
Ajey Golsangi:
2011-09-18 13:38:47
I got a WA due to 'knight'. Please don't leave an empty line b/w outputs. |
|
Santiago Palacio:
2011-04-13 18:49:29
@cegprakash i believe none of them is correct, the "battles" occurs insantly, ergo, it will be
|
|
cegprakash:
2011-04-09 11:44:23
consider this case
|
|
Knight:
2011-03-23 08:01:44
Egor is right !!!
|
|
:D:
2011-03-23 08:01:44
N seems to be "small". |
|
Egor:
2011-03-23 08:01:44
Don't print newline between output testcases! |
|
Oleg:
2011-03-23 08:01:44
What range n has ? |
Added by: | Infinity |
Date: | 2011-03-21 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ADA95 ASM32 ASM64 BASH CLPS CLOJURE LISP sbcl LISP clisp D ERL FSHARP FORTRAN GO ICON ICK LUA NEM NICE OCAML PIKE PRLG-swi SCM guile SCM qobi ST TCL WHITESPACE |
Resource: | Own |