题意:
有两块n * m的图,现在给出n * m的0/1图,1表示这两张图这个地方都染过色,并且保证不会在边界上,0表示都没有,现在知道的是这两张图染色的格子都是联通块,现在求这些格子的染色情况。
题解:
这题我一眼上去就是DFS啊,我去构造题啊,智商被碾压了QAQ
这样构造然后再将都有的部分加入,那么都是联通块辣!
代码:
#include <bits/stdc++.h> using namespace std; const int N = 5e2 + 7; int n, m, mp[N][N], ans1[N][N], ans2[N][N]; int main () { scanf ("%d%d", &n, &m); for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) { scanf ("%1d", &mp[i][j]); } for (int i = 1; i <= n; ++i) { ans1[i][1] = 1; for (int j = 1; j <= m; ++j) if (mp[i][j]) ans1[i][j] = 1; if ((i & 1) == 1) for (int j = 2; j <= m - 1; ++j) ans1[i][j] = 1; } for (int i = 1; i <= n; ++i) { ans2[i][m] = 1; for (int j = 1; j <= m; ++j) if (mp[i][j]) ans2[i][j] = 1; if ((i & 1) == 0) for (int j = m - 1; j >= 2; --j) ans2[i][j] = 1; } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) printf ("%d", ans1[i][j]); cout << endl; } cout << endl; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) printf ("%d", ans2[i][j]); cout << endl; } return 0; }
总结:
仔细看清题目的条件,然后再根据某些性质搞一搞。