poj 2339 Rock, Scissors, Paper

Rock, Scissors, Paper
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 3845 Accepted: 2245

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


思路:引用两个矩阵。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <queue>


using namespace std;
#define maxn 105
#define inf 0x7ffffff
char arr[2][maxn][maxn];
char h[128];
int t,n,m,c;
int now,next;
void sovle(char ch,int x,int y);
int main()
{
    h['P'] = 'S';
    h['R'] = 'P';
    h['S'] = 'R';
    scanf("%d",&t);
    while(t--){
        now = 0, next = 1;
        scanf("%d%d%d",&n,&m,&c);
        getchar();
        for(int i = 0; i < n ;i++){
            gets(arr[0][i]);
        }
        while(c--){
            for(int i = 0; i < n; i++){
                for(int j = 0; j < m ; j++){
                    sovle(arr[now][i][j],i,j);
                }
            }
            now = next;
            next ^= now;
        }
        for(int i = 0; i < n; i++){
            puts(arr[now][i]);
        }
            printf("\n");
    }
    return 0;
}
void sovle(char ch,int x,int y){
    char tmp = h[ch];
    if(arr[now][x-1][y] == tmp || arr[now][x+1][y] == tmp || arr[now][x][y-1] == tmp || arr[now][x][y+1] == tmp){
        arr[next][x][y] = tmp;
    }else{
        arr[next][x][y] = ch;
    }
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值