动态规划
#include <stdio.h>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
const int LEN = 101;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
char hash[26];
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int r, c, n;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
char map[LEN][LEN];
char cmap[LEN][LEN];
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
void cpy ()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for ( int i=0; i<r; i++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for ( int j=0; j<c; j++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
map[i][j] = cmap[i][j];
}
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) int move[4][2] = { 0, 1, 1, 0, 0, -1, -1, 0 };
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
void ser ()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
hash[ 'R'-'A' ] = 'S';
hash[ 'S'-'A' ] = 'P';
hash[ 'P'-'A' ] = 'R';
int flag = 1;
for ( int i=0; i<n; i++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
flag = 0;
for ( int j=0; j<r; j++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for ( int z=0; z<c; z++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
int tr, tc;
for ( int x =0; x<4; x++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
tr = j+move[x][0];
tc = z+move[x][1];
if ( tr>=0 && tr<r && tc>=0 && tc<c )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if ( hash[ map[tr][tc]-'A' ] == map[j][z] )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
cmap[j][z] = map[tr][tc];
flag = 1;
break;
}
}
}
if ( x >= 4 )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
cmap[j][z] = map[j][z];
}
}
}
cpy ();
if ( ! flag )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
break;
}
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int main ()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int t;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
scanf ( "%d", &t );
while ( t -- )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
scanf ( "%d%d%d", &r, &c, &n );
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
getchar ();
for ( int i=0; i<r; i++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for ( int j=0; j<c; j++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
scanf ( "%c", &map[i][j] );
}
getchar ();
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
ser ();
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for ( i=0; i<r; i++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for ( int j=0; j<c; j++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
printf ( "%c", map[i][j] );
}
printf ( "\n" );
}
printf ( "\n" );
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
}
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
|
|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
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)
随笔档案
搜索
最新评论
![](/images/xml.gif)
阅读排行榜
评论排行榜
|
|