* 每行的黑色方块数与白色方块数相同。
* 每列的黑色正方形数与白色方块数相同。
* 没有行或列具有 3 3 3 个及以上相同颜色的连续正方形。

<>输入格式

<>输出格式

<>样例输入
4 WBBW WBWB BWWB BWBW
<>样例输出
1
<>解题思路

（1）与当前连续色块颜色一致：色块连续数++

（2）与当前连续色块颜色不一致：修改当前连续色块颜色，初始化色块连续数为 1 1 1

AC代码如下
#include <iostream> #include <string> using namespace std; const int max_n = 24
; int n; int row_sum, row_seq, row_status = -1; int col_sum[max_n], col_seq[
max_n], col_status[max_n]; int main() { for (int i = 0; i < max_n; i++)
col_status[i] = -1; cin >> n; cin.ignore(); string str; bool ans = true, c; for
(int i = 0; i < n; i++) { getline(cin, str); int len = str.size(); if (ans) {
for (int j = 0; j < len; j++) { if (str[j] == 'B') c = 1; else c = 0; row_sum +=
c; if (row_status == c) { row_seq++; if (row_seq == 3) { ans = false; break; }
} else { row_seq = 1; row_status = c; } col_sum[j] += c; if (col_status[j] == c)
{ col_seq[j]++; if (col_seq[j] == 3) { ans = false; break; } } else { col_seq[j]
= 1; col_status[j] = c; } } if (row_sum != n / 2) ans = false; row_sum = 0;
row_seq= 0; row_status = -1; } } if (ans) { for (int i = 0; i < n; i++) if (
col_sum[i] != n / 2) { ans = false; break; } } cout << ans << endl; return 0; }

GitHub

Gitee