算法
(爆搜) $O(HW)$
扫描每个 .
周围的点分别染了什么颜色,并做一个标记,然后在没有做标记的颜色中找一种给这个点染色即可
C++ 代码
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using std::cin;
using std::cout;
using std::vector;
using std::string;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
rep(i, h) cin >> s[i];
rep(i, h)rep(j, w) {
if (s[i][j] != '.') continue;
vector<bool> ok(5);
rep(v, 4) {
int ni = i + di[v], nj = j + dj[v];
if (ni < 0 or nj < 0 or ni >= h or nj >= w or s[ni][nj] == '.') continue;
ok[s[ni][nj]-'1'] = true;
}
rep(k, 5) if (!ok[k]) s[i][j] = '1' + k;
}
rep(i, h) cout << s[i] << '\n';
return 0;
}