ZQUOJ1396 Rock, Scissors, Paper 解題報告

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代碼:

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章