pku 2339 Rock, Scissors, Paper 水题啊水题

pku 2339 Rock, Scissors, Paper 水题啊水题

由于是水题,就描述题意然后贴代码了。。
有3种生物R,S,P,占领了网格图中的某些格子,每天,3种生物在交界处打架,打赢的在凌晨将打输的驱逐出那个格子,并且占领那个格子。问K天后网格图中的状况。
 1  # include  < cstdio >
 2  # include  < cstring >
 3  # define legal(a,b) ((a) >= 0 && (a) < r && (b) >= 0 && (b) < c)
 4  using   namespace  std;
 5  char  map[ 105 ][ 105 ];
 6  char  tmp[ 105 ][ 105 ];
 7  int  main()
 8  {
 9       int  testcase;
10      scanf( " %d " , & testcase);
11       while (testcase -- )
12      {
13           int  r,c,n;
14          scanf( " %d%d%d " , & r, & c, & n);
15           for ( int  i = 0 ;i < r;i ++ )
16            scanf( " %s " ,map[i]);
17           for ( int  i = 1 ;i <= n;i ++ )
18          {
19              memcpy(tmp,map, sizeof (map));
20               for ( int  ii = 0 ;ii < r;ii ++ )
21                 for ( int  jj = 0 ;jj < c;jj ++ )
22                    switch (map[ii][jj])
23                   {
24                       case   ' R ' :
25                            if (legal(ii - 1 ,jj) && map[ii - 1 ][jj] == ' P ' )
26                              tmp[ii][jj] = ' P ' ;
27                            if (legal(ii + 1 ,jj) && map[ii + 1 ][jj] == ' P ' )
28                              tmp[ii][jj] = ' P ' ;
29                            if (legal(ii,jj + 1 ) && map[ii][jj + 1 ] == ' P ' )
30                              tmp[ii][jj] = ' P ' ;
31                            if (legal(ii,jj - 1 ) && map[ii][jj - 1 ] == ' P ' )
32                              tmp[ii][jj] = ' P ' ;
33                            break ;
34                       case   ' S ' :
35                            if (legal(ii - 1 ,jj) && map[ii - 1 ][jj] == ' R ' )
36                              tmp[ii][jj] = ' R ' ;
37                            if (legal(ii + 1 ,jj) && map[ii + 1 ][jj] == ' R ' )
38                              tmp[ii][jj] = ' R ' ;
39                            if (legal(ii,jj + 1 ) && map[ii][jj + 1 ] == ' R ' )
40                              tmp[ii][jj] = ' R ' ;
41                            if (legal(ii,jj - 1 ) && map[ii][jj - 1 ] == ' R ' )
42                              tmp[ii][jj] = ' R ' ;
43                            break ;
44                       case   ' P ' :
45                            if (legal(ii - 1 ,jj) && map[ii - 1 ][jj] == ' S ' )
46                              tmp[ii][jj] = ' S ' ;
47                            if (legal(ii + 1 ,jj) && map[ii + 1 ][jj] == ' S ' )
48                              tmp[ii][jj] = ' S ' ;
49                            if (legal(ii,jj + 1 ) && map[ii][jj + 1 ] == ' S ' )
50                              tmp[ii][jj] = ' S ' ;
51                            if (legal(ii,jj - 1 ) && map[ii][jj - 1 ] == ' S ' )
52                              tmp[ii][jj] = ' S ' ;
53                            break ;
54                   };
55              memcpy(map,tmp, sizeof (map));
56          }
57           for ( int  i = 0 ;i < r;i ++ )
58             printf( " %s\n " ,map[i]);
59          printf( " \n " );
60      }
61       // scanf("%d",&testcase);
62       return   0 ;
63  }
64 


你可能感兴趣的:(pku 2339 Rock, Scissors, Paper 水题啊水题)