#include
#include
#include
#include
#include
#include
#include
#include
using
namespace std;
int n;
int arr[50]
[50];
int vis[50]
[50];
int xx=
;int yy=
;//上下左右
void
bfs()}
xq.pop(
), yq.
pop();
//父節點出隊}}
intmain()
bfs();
for(
int i =
1; i <= n; i++
) cout << endl;
}return0;
}
bfs理解起來不難,我們再看一下dfs怎麼做,依然是之前的思路,只是換了乙個搜尋方法而已,顯然,dfs寫起來更簡潔一點
#include
#include
#include
#include
#include
#include
#include
#include
using
namespace std;
int n;
int arr[50]
[50];
int vis[50]
[50];
//標記陣列
int xx=
;//方向陣列
int yy=
;//上下左右
void
dfs(
int x,
int y)
}int
main()
dfs(0,
0);for
(int i =
1; i <= n; i++
) cout << endl;
}return0;
}
洛谷P1162 填塗顏色
由數字0組成的方陣中,有一任意形狀閉合圈,閉合圈由數字1構成,圍圈時只走上下左右4個方向。現要求把閉合圈內的所有空間都填寫成2.例如 6 6的方陣 n 6 塗色前和塗色後的方陣如下 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 1 0 0 0 0 1...
填塗顏色 洛谷P1162
由數字0組成的方陣中,有一任意形狀閉合圈,閉合圈由數字1構成,圍圈時只走上下左右4個方向。現要求把閉合圈內的所有空間都填寫成2.例如 6 6的方陣 n 6 塗色前和塗色後的方陣如下 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 1 0 0 0 0 1...
洛谷P1162 填塗顏色
題目描述 由數字0組成的方陣中,有一任意形狀閉合圈,閉合圈由數字1構成,圍圈時只走上下左右4個方向。現要求把閉合圈內的所有空間都填寫成2,例如 6 6的方陣 n 6 塗色前和塗色後的方陣如下 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 1 0 0 ...