UVA 705 - Slash Maze (Flood_Fill + DFS)
分析: 1. 可以知道的是,給定的 slash Maze 中只存在 ‘/’ 和 ‘\’ ,將斜線或反斜線離散化為 3 * 3 單位的方格,比如 用數字 1 表示單位被覆蓋,數字 0 表示單位是空白,則 / 0 0 1 0 1 0 1 0 0 也可以用 2 * 2 的單元格表示圖像,但是需要特判,而這種方法不需要特判,而且相對容易實現 2. 對圖像的邊界使用 Flood Fill 染色為數字 2,因為邊界部分不可能構成環(想一想),排除不構成環的部分 3. 第 2 步以后,對 slash Maze 數字為 0 的空格使用 dfs 找出最大的環長度,也可以使用 flood fill 直接找出 1 /* 2 PROG: Slash Maze 3 ID : yewei 4 LANG: C++ 5 */ 6 #pragma warnning (disable : 4786) 7 8 #include <memory.h> 9 #include <cstdio> 10 #include <cstdlib> 11 #include <cstring> 12 #include <iostream> 13 14 using namespace std; 15 16 const int MAXN = 229 ; 17 const int dx[] = {- 1 , 1 , 0 , 0 }; 18