当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5535:Chess Puzzle

题目描述
Andrew is a puzzle lover, he is interested in creating interesting puzzles. One day he creates a new puzzle, following are the rules of the game:

The game is played on a big chessboard, it has $n$ rows and $m$ columns. The coordination $(i,j)$ ($1 \le i \le n$ ,$1 \le j \le m$) indicates the square on $i$-th row and $j$-th column.

There are two kinds of chesses, black chess and white chess in this game. Some of the chesses are putted on some squares at the initial of the game, and other squares are empty.

The player has to put chesses on all the empty squares. Both black and white chesses are sufficient enough to be putted on all the squares.

After all the squares on chessboard are full of chess. Andrew begins to calculate the score that player gets. The score is calculated using the following algorithm - For every two squares $(x_1, y_1)$ and $(x_2,y_2)$, the player gets $1$ point if the following $3$ conditions are satisifed:

- There is a black chess on $(x_1, y_1)$.
- And a white chess on $(x_2, y_2)$.
- $|x_1 - x_2|=a$ and $|y_1 - y_2| = b$, which $a$ and $b$ are two constants defined by Andrew before the game starts.

But Andrew is confused because he doesn't know what is the highest possiple score in the game. Can you help him find the best way to solve the puzzle?
输入解释
The first line of input contains an integer $T$ indicating the total number of test cases.

The first line of each test case has 4 integers $n, m, a, b$, indicating the number of rows, number of columns and two integers decided by Andrew. The $n$ lines that follow describe the puzzle, the $i$-th of these lines is a string with $m$ characters $c_{i,1}, c_{i,2},..., c_{i,m}$, which $c_{i,j}$ indicates the type of chess that putted on $(i,j)$ at the begin of game. Black chesses are represented by uppercase ('B'), white chesses by uppercase ('W'), and empty squares by period ('.').

$1 \le T \le 1000$
$1 \le n,m \le 100$
$1 \le a \le n$, $1 \le b \le m$
There are at most $20$ testcases with $n > 30$ or $m > 30$
输出解释
For each test case, please output an integer in the first line indicating the highest score that player can get. Then following $n$ lines, each line with $m$ characters indicating the chess type on each square to get the higgest score. The output format is same as input format.

Note that if there are mutiple ways to get the highest score, you should output the one with smallest lexicographical order in ASCII. ('B' is smaller than 'W')
输入样例
2
2 2 1 1
..
..
2 2 1 1
.W
.B
输出样例
2
BB
WW
2
WW
BB
来自杭电HDUOJ的附加信息
Recommend hujie

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5535

最后修改于 2020-10-25T23:23:32+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
16000/8000MS(Java/Others) 262144/262144K(Java/Others)