Rock, Scissors, Paper
Time limit1sMemory limit128 MB
Given a grid of Rock, Scissors, and Paper cells, simulate simultaneous battles each day and print the grid after n days.
- Level
Medium5 of 10
- Topics
- Simulation, Matrix, Implementation
- Solved
- No attempts yet
Problem
Bart's sister Lisa has built a new civilization on a two-dimensional grid. At the start, each grid cell may be occupied by one of three life forms: Rock, Scissors, or Paper. Each day, whenever two horizontally or vertically adjacent cells hold different life forms, they wage war. In every war Rock always beats Scissors, Scissors always beats Paper, and Paper always beats Rock. At the end of the day the winner expands into the loser's cell and takes it over, while the loser disappears from that cell. All of the wars on a given day happen simultaneously.
Determine the territory occupied by each life form after days.
Input
The first line contains , the number of test cases. Each test case begins with three integers , , and : the number of rows, the number of columns, and the number of days that pass. Each of these integers is at most 100. The next lines describe the grid, each containing characters. Every character is R, S, or P, meaning that the cell is occupied by Rock, Scissors, or Paper respectively.
Output
For each test case, print the grid as it appears at the end of day . Print one empty line between the outputs of successive test cases.