POJ - 2339 Rock, Scissors, Paper

初看题目时就发了个错误,我因为没有耐心看题而不了解题目本身的意思,找不到做题的突破口,即使看了一些题解,还是没有想到方法。

后来在去问安叔,安叔一语道破天机,问我有没有搞清题目的意思,我才恍然大悟,做题当然要先搞懂题目意思,不然做什么题呢!以后一定要再三注意!而且要把每一个细节都注意到!

POJ - 2339 Rock, Scissors, Paper

Time Limit: 5000MS

 

Memory Limit: 65536KB

 

64bit IO Format: %I64d & %I64u

 

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

Waterloo local 2003.01.25

 

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<math.h>
 4 #include<stdlib.h>
 5 char toda[105][105];
 6 char tomo[105][105];
 7 int main()
 8 {
 9     int t = 0, r = 0, c = 0, n = 0, i = 0, j = 0;
10     scanf("%d", &t);
11     while(t--) {
12         scanf("%d%d%d", &r, &c, &n);
13         for(i = 0; i < r; i++) {
14             scanf("%s", toda[i]);
15         }
16         for(i = 0; i < r; i++) {
17             for(j = 0; j < c; j++) {
18                 tomo[i][j] = toda[i][j];
19             }
20         }
21         while(n--) {
22             for(i = 0; i < r; i++) {
23                 for(j = 0; j < c; j++) {
24                     if(toda[i][j] == 'R') {
25                         if(j+1 < c && toda[i][j+1] == 'S')
26                             tomo[i][j+1] = 'R';
27                         if(i-1 >= 0 && toda[i-1][j] == 'S')
28                             tomo[i-1][j] = 'R';
29                         if(j-1 >= 0 && toda[i][j-1] == 'S')
30                             tomo[i][j-1] = 'R';
31                         if(i+1 < r && toda[i+1][j] == 'S')
32                             tomo[i+1][j] = 'R';
33                     }
34                     else if(toda[i][j] == 'S') {
35                         if(j+1 < c && toda[i][j+1] == 'P')
36                             tomo[i][j+1] = 'S';
37                         if(i-1 >= 0 && toda[i-1][j] == 'P')
38                             tomo[i-1][j] = 'S';
39                         if(j-1 >= 0 && toda[i][j-1] == 'P')
40                             tomo[i][j-1] = 'S';
41                         if(i+1 < r && toda[i+1][j] == 'P')
42                             tomo[i+1][j] = 'S';
43                     }
44                     else {
45                         if(j+1 < c && toda[i][j+1] == 'R')
46                             tomo[i][j+1] = 'P';
47                         if(i-1 >= 0 && toda[i-1][j] == 'R')
48                             tomo[i-1][j] = 'P';
49                         if(j-1 >= 0 && toda[i][j-1] == 'R')
50                             tomo[i][j-1] = 'P';
51                         if(i+1 < r && toda[i+1][j] == 'R')
52                             tomo[i+1][j] = 'P';
53                     }
54                 }
55             }
56             for(i = 0; i < r; i++) {
57                 for(j = 0; j < c; j++) {
58                     toda[i][j] = tomo[i][j];
59                 }
60             }
61         }
62         for(i = 0; i < r; i++) {
63             for(j = 0; j < c; j++) {
64                 printf("%c", toda[i][j]);
65             }
66             printf("\n");
67         }
68         if(n) printf("\n");
69     }
70     return 0;
71 }

 

转载于:https://www.cnblogs.com/acmicky/p/3221426.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值