CF1534A.Colour the Flag
入门
通过率:0%
时间限制:1.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Today we will be playing a red and white colouring game (no, this is not the Russian Civil War; these are just the colours of the Canadian flag).
You are given an n×m grid of "R", "W", and "." characters. "R" is red, "W" is white and "." is blank. The neighbours of a cell are those that share an edge with it (those that only share a corner do not count).
Your job is to colour the blank cells red or white so that every red cell only has white neighbours (and no red ones) and every white cell only has red neighbours (and no white ones). You are not allowed to recolour already coloured cells.
今天我们将玩一个红白配色游戏(不,这与俄国内战无关;这只是加拿大国旗的颜色)。
你将得到一个 n×m 的网格,其中包含字符 "R"、"W" 和 "."。"R" 表示红色,"W" 表示白色,"." 表示空白格。一个格子的邻居是指与其共享一条边(即上下左右)的格子(仅共享顶点的格子不算邻居)。
你的任务是将所有空白格(".")染成红色或白色,使得:每个红色格子的所有邻居均为白色(不能有红色邻居),且每个白色格子的所有邻居均为红色(不能有白色邻居)。已染色的格子("R" 或 "W")不允许重新染色。
输入格式
The first line contains t (1≤t≤100), the number of test cases.
In each test case, the first line will contain n (1≤n≤50) and m (1≤m≤50), the height and width of the grid respectively.
The next n lines will contain the grid. Each character of the grid is either 'R', 'W', or '.'.
第一行包含 t(1≤t≤100),表示测试用例的数量。
对于每个测试用例,第一行包含两个整数 n(1≤n≤50)和 m(1≤m≤50),分别表示网格的高度和宽度。
接下来的 n 行描述该网格。网格中的每个字符为 'R'、'W' 或 '.'。
输出格式
For each test case, output "YES" if there is a valid grid or "NO" if there is not.
If there is, output the grid on the next n lines. If there are multiple answers, print any.
In the output, the "YES"s and "NO"s are case-insensitive, meaning that outputs such as "yEs" and "nO" are valid. However, the grid is case-sensitive.
对于每个测试用例,如果存在合法的网格,则输出 "YES";否则输出 "NO"。
如果存在合法网格,则在接下来的 n 行中输出该网格。如果有多个合法答案,输出任意一个即可。
在输出中,"YES" 和 "NO" 不区分大小写,即诸如 "yEs" 和 "nO" 的输出是合法的。但网格本身区分大小写。
输入输出样例
输入#1
3 4 6 .R.... ...... ...... .W.... 4 4 .R.W .... .... .... 5 1 R W R W R
输出#1
YES WRWRWR RWRWRW WRWRWR RWRWRW NO YES R W R W R
说明/提示
The answer for the first example case is given in the example output, and it can be proven that no grid exists that satisfies the requirements of the second example case. In the third example all cells are initially coloured, and the colouring is valid.
第一个样例的输出已在示例输出中给出;可以证明,第二个样例不存在满足要求的网格。在第三个样例中,所有格子初始时均已着色,且该着色是合法的。
输入解题思路,AI测评打分。不知道怎么写?