Backtracking DFS method

1. Seize the board.
In the process of playing chess, if the white or black stones surround the opponent, the stones in the enclosed area will change colors. Use 1 to represent sunspots and 0 to represent whites. The following example is given:
1111
0101
1101
0010
because the whites (0) in the second row and the third column and the whites (0) in the third row and the third column are all surrounded by the blacks. Two 0s become 1. The result becomes:
1111
0111
1111
0010
In order to simplify the problem, just find all the whites surrounded by blacks.
Enter description:

Single input.
The first row: n (n<=1000), which means the size of the chessboard.
Enter the n×n 0/1 matrix in the next n rows

Output description:

Output the 0/1 matrix after conversion

#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>

using namespace std;

const int dir[4][2

Guess you like

Origin blog.csdn.net/qq_43265072/article/details/108589180