动态规划
#include <stdio.h>
const int LEN = 101;
char hash[26];
int r, c, n;
char map[LEN][LEN]; char cmap[LEN][LEN];
void cpy () {
for ( int i=0; i<r; i++ ) { for ( int j=0; j<c; j++ ) { map[i][j] = cmap[i][j]; } } }
int move[4][2] = { 0, 1, 1, 0, 0, -1, -1, 0 };
void ser () {
hash[ 'R'-'A' ] = 'S'; hash[ 'S'-'A' ] = 'P'; hash[ 'P'-'A' ] = 'R'; int flag = 1; for ( int i=0; i<n; i++ ) { flag = 0; for ( int j=0; j<r; j++ ) { for ( int z=0; z<c; z++ ) { int tr, tc; for ( int x =0; x<4; x++ ) { tr = j+move[x][0]; tc = z+move[x][1]; if ( tr>=0 && tr<r && tc>=0 && tc<c ) { if ( hash[ map[tr][tc]-'A' ] == map[j][z] ) { cmap[j][z] = map[tr][tc]; flag = 1; break; } } } if ( x >= 4 ) { cmap[j][z] = map[j][z]; } } } cpy (); if ( ! flag ) { break; } } }
int main () {
int t;
scanf ( "%d", &t ); while ( t -- ) { scanf ( "%d%d%d", &r, &c, &n );
getchar (); for ( int i=0; i<r; i++ ) { for ( int j=0; j<c; j++ ) { scanf ( "%c", &map[i][j] ); } getchar (); }
ser ();
for ( i=0; i<r; i++ ) { for ( int j=0; j<c; j++ ) { printf ( "%c", map[i][j] ); } printf ( "\n" ); } printf ( "\n" );
} return 0; }
|
|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
25 | 26 | 27 | 28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 1 | 2 | 3 | 4 | 5 |
|
公告
决定从线程开始!!
常用链接
留言簿(6)
随笔档案
搜索
最新评论
阅读排行榜
评论排行榜
|
|