Rock, Scissors, Paper
memory limit: 65536KB time limit: 2500MS
accept: 18 submit: 44
Description
Bart's sister Lisa has created a new civilization on a two-dimensional grid. At the outset each grid location may be occupied by one of three life forms: Rocks, Scissors, or Papers. Each day, differing life forms occupying horizontally or vertically adjacent grid locations wage war. In each war, Rocks always defeat Scissors, Scissors always defeat Papers, and Papers always defeat Rocks. At the end of the day, the victor expands its territory to include the loser's grid position. The loser vacates the position.
Your job is to 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 R, S, or P, indicating that it is occupied by Rocks, Scissors, or Papers respectively.
Output
For each test case, print the grid as it appears at the end of the nth day. Leave an empty line between the output for successive test cases.
Sample Input
2
3 3 1
RRR
RSR
RRR
3 4 2
RSPR
SPRS
PRSP
Sample Output
RRR
RRR
RRR
RRRS
RRSP
RSPR
Source
ZQUCPC个人赛4
Author
Waterloo local
题意:
剪刀石头布,给出一个二维矩阵,每个位置是三种状态的一种,每一天三种状态可以取代四周对应的状态,剪刀取代布,布取代石头,石头取代剪刀,求n天后该矩阵的状态。
提交次数:
1次AC
总耗时:
大约半小时
问题的分析与解题思路:
这是一个水题,用两个矩阵,一个用来保存第n天没改变前的状态,另一个用来保存第n天改变后的状态,直接遍历改变前状态的那个矩阵,然后将每一个位置四周要改变的情况在第二个矩阵体现,然后将第二个矩阵复制到第一个,反复n次即可。
AC方法和数据结构:
直接遍历。
AC代码: