本文共 1353 字,大约阅读时间需要 4 分钟。
1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include 16 using namespace std;17 #define PI acos(-1.0)18 #define INF 0x3f3f3f3f19 #define MAX 100520 #define MST(a,b) memset(a,b,sizeof(a))21 #define MOD 2012122322 #define EPS 1e-623 #define pp(a) cout << a << endl;24 typedef long long LL;25 typedef unsigned long long LLU;26 char m[MAX][MAX];27 int r,c;28 int finde;29 int dx[] = { 0,0,-1,1};30 int dy[] = { 1,-1,0,0};31 int vis[MAX][MAX];32 void dfs(int x,int y) {33 if(m[x][y] == 'H') {34 finde = 1;35 return ;36 }37 for(int i = 0;i < 4;i ++) {38 int nx = x + dx[i];39 int ny = y + dy[i];40 if(nx >= 0 && nx < r && ny >= 0 && ny < c && m[nx][ny] != '#' && !vis[nx][ny]) {41 vis[nx][ny] = 1;42 dfs(nx,ny);43 if(finde) return ;44 vis[nx][ny] = 0;45 }46 }47 }48 int main(void) {49 finde = 0;50 MST(vis,0);51 cin >> r;52 cin >> c;53 int x,y;54 for(int i = 0;i < r;i ++) {55 for(int j = 0;j < c;j ++) {56 cin >> m[i][j];57 if(m[i][j] == 'B') {58 x = i;59 y = j;60 }61 }62 }63 dfs(x,y);64 if(finde) cout << "Y" << endl;65 else cout << "N" << endl;66 return 0;67 }
转载于:https://www.cnblogs.com/mitrenick/p/3717911.html