Topic: Http://codeforces.com/problemset/problem/515/D : Give you a square, ask you to fill the square with 1x2, some squares have been occupied (with ' * '), not occupied ('. ') )。 Put up to fill, with "^v" said, horizontal up, with "<>" said. If you put the method unique, the output of the square chart. Otherwise, the output is not unique. Analysis: DFS, a pair of to find. Input
3 3
...
.*.
...
Output
Not unique
Input
4 4
.. **
*...
*.**
....
Output
<>**
*^<>
*v**
<><>
#include <bits/stdc++.h> using namespace std;
int const MAX = 2010;
Char S[max][max];
int n, m, CNT;
int dx[4] = {0, 0, 1,-1};
int dy[4] = {1,-1, 0, 0};
void Dfs (int x, int y) {if (x < 1 | | x > N | | y < 1 | | y > M | | s[x][y]!= '. ')
Return
int dir =-1, sum = 0;
for (int i = 0; i < 4; i++) {int xx = x + dx[i];
int yy = y + dy[i];
if (s[xx][yy] = = '. ')
{sum + +;
dir = i;
} if (sum = = 1) {if (dir = = 0) {S[x][y] = ' < ';
S[x][y + 1] = ' > ';
else if (dir = = 1) {S[x][y] = ' > ';
S[x][y-1] = ' < ';
else if (dir = = 2) {S[x][y] = ' ^ ';
S[x + 1][y] = ' V ';
else if (dir = = 3) {S[x][y] = ' V ';
S[x-1][y] = ' ^ ';
CNT = 2;
for (int i = 0; i < 4; i++) DFS (x + dx[dir] + dx[i], y + dy[dir] + dy[i]);
} void Init () {cnt = 0; for (int i = 1; I <= n; i++) for (int j = 1; j <= m; j) if (s[i][j] = = ' * ') CNT +
+;
int main () {scanf ("%d%d", &n, &m);
for (int i = 1; I <= n; i++) scanf ("%s", S[i] + 1);
Init ();
for (int i = 1; I <= n; i++) for (int j = 1; j <= m; j) Dfs (I, j);
if (CNT = n * m) {for (int i = 1; I <= n; i++) {printf ("%s\n", S[i] + 1);
else printf ("Not unique\n");
return 0;
}