简单BFS。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <queue> 6 using namespace std; 7 8 #define MAXN 105 9 10 typedef struct node_t { 11 int x, y; 12 node_t() {} 13 node_t(int xx, int yy) { 14 x = xx; y = yy; 15 } 16 } node_t; 17 18 char map[MAXN][MAXN]; 19 char ans[MAXN][MAXN]; 20 bool visit[MAXN][MAXN]; 21 int dir[8][2] = { 22 {-1,0},{1,0},{0,1},{0,-1}, 23 {1,1},{1,-1},{-1,1},{-1,-1} 24 }; 25 node_t s; 26 int n; 27 28 bool check(int x, int y) { 29 return x<0 || x>=n || y<0 || y>=n; 30 } 31 32 void bfs() { 33 int i, j, k, tmp; 34 int x, y, v; 35 int xx[8], yy[8], m; 36 queue<node_t> Q; 37 node_t nd; 38 39 memset(visit, false, sizeof(visit)); 40 memset(ans, '.', sizeof(ans)); 41 visit[s.x][s.y] = true; 42 for (i=0; i<n; ++i) 43 ans[i][n] = '