311048: CF1926F. Vlad and Avoiding X

Memory Limit:256 MB Time Limit:4 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Vlad and Avoiding Xtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Vladislav has a grid of size $7 \times 7$, where each cell is colored black or white. In one operation, he can choose any cell and change its color (black $\leftrightarrow$ white).

Find the minimum number of operations required to ensure that there are no black cells with four diagonal neighbors also being black.

The left image shows that initially there are two black cells violating the condition. By flipping one cell, the grid will work.

Input

The first line of input contains a single integer $t$ ($1 \leq t \leq 200$) — the number of test cases. Then follows the description of the test cases.

Each test case consists of $7$ lines, each containing $7$ characters. Each of these characters is either $\texttt{W}$ or $\texttt{B}$, denoting a white or black cell, respectively.

Output

For each test case, output a single integer — the minimum number of operations required to ensure that there are no black cells with all four diagonal neighbors also being black.

ExampleInput
4
WWWWWWW
WWWWBBB
WWWWWBW
WWBBBBB
WWWBWWW
WWBBBWW
WWWWWWW
WWWWWWW
WWWWWWW
WBBBBBW
WBBBBBW
WBBBBBW
WWWWWWW
WWWWWWW
WWWWWWW
WWWWWWW
WWWWWWW
WWWWWWW
WWWWWWW
WWWWWWW
WWWWWWW
WBBBBBW
BBBBBBB
BBBBBBB
WWWWWWW
BBBBBBB
BBBBBBB
BBBBBBB
Output
1
2
0
5
Note

The first test case is illustrated in the statement.

The second test case is illustrated below:

In the third test case, the grid already satisfies the condition.

Output

题目大意:
弗拉德有一个7x7的网格,每个单元格被涂成黑色或白色。在一次操作中,他可以选择任何一个单元格并改变其颜色(黑色<->白色)。求最少需要多少次操作,以确保没有黑色单元格的四个对角邻居也是黑色。

输入数据格式:
第一行输入一个整数t(1≤t≤200)——测试用例的数量。接下来是测试用例的描述。每个测试用例由7行组成,每行包含7个字符。这些字符要么是`W`,要么是`B`,分别表示白色或黑色单元格。

输出数据格式:
对于每个测试用例,输出一个整数——确保没有黑色单元格的四个对角邻居也是黑色所需的最少操作次数。

示例:
输入:
```
4
WWWWWWW
WWWWBBB
WWWWWBW
WWBBBBB
WWWBWWW
WWBBBWW
WWWWWWW
WWWWWWW
WWWWWWW
WBBBBBW
WBBBBBW
WBBBBBW
WWWWWWW
WWWWWWW
WWWWWWW
WWWWWWW
WWWWWWW
WWWWWWW
WWWWWWW
WBBBBBW
BBBBBBB
BBBBBBB
WWWWWWW
BBBBBBB
BBBBBBB
BBBBBBB
```
输出:
```
1
2
0
5
```题目大意: 弗拉德有一个7x7的网格,每个单元格被涂成黑色或白色。在一次操作中,他可以选择任何一个单元格并改变其颜色(黑色<->白色)。求最少需要多少次操作,以确保没有黑色单元格的四个对角邻居也是黑色。 输入数据格式: 第一行输入一个整数t(1≤t≤200)——测试用例的数量。接下来是测试用例的描述。每个测试用例由7行组成,每行包含7个字符。这些字符要么是`W`,要么是`B`,分别表示白色或黑色单元格。 输出数据格式: 对于每个测试用例,输出一个整数——确保没有黑色单元格的四个对角邻居也是黑色所需的最少操作次数。 示例: 输入: ``` 4 WWWWWWW WWWWBBB WWWWWBW WWBBBBB WWWBWWW WWBBBWW WWWWWWW WWWWWWW WWWWWWW WBBBBBW WBBBBBW WBBBBBW WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW WWWWWWW WBBBBBW BBBBBBB BBBBBBB WWWWWWW BBBBBBB BBBBBBB BBBBBBB ``` 输出: ``` 1 2 0 5 ```

加入题单

上一题 下一题 算法标签: