[CF445A] DZY Loves Chessboard

[CF445A] DZY Loves Chessboard

一个棋盘上有一些格子是坏的,另一些是正常的。对于每一个正常的格子,都要在上面放上棋子。请找到一组解使没有两个相同颜色的棋子相邻。

Solution

按坐标染色最省事

#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main()
{
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    string str;
    for (int i = 1; i <= n; i++)
    {
        cin >> str;
        str = " " + str;
        for (int j = 1; j <= m; j++)
        {
            if (str[j] == '.')
                str[j] = (i + j) % 2 ? 'W' : 'B';
        }
        cout << str << endl;
    }
}
原文地址:https://www.cnblogs.com/mollnn/p/14429737.html