#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int i, j, k; int h, w, sx, sy, gx, gy; vectorb; vector>matrix(100, vector(100, false)); int func(int x, int y) { cout << "x->" << x << " y->" << y << endl; for (int i = 0; i <= h; i++) { for (int j = 0; j <= w; j++) { cout << matrix[i][j] << " "; } cout << endl; } cout << endl; cout << endl; if (x == gx && y == gy) { cout << "YES" << endl; getchar(); getchar(); exit(0); //return 0; } int taka = (int)b[y][x] - 48; if (y - 1 >= 0 && matrix[y - 1][x] == false && abs(taka - ((int)b[y - 1][x] - 48)) <= 1) { matrix[y - 1][x] = true; func(x, y - 1); } if (y + 1 <= h && matrix[y + 1][x] == false && abs(taka - ((int)b[y + 1][x] - 48)) <= 1) { matrix[y + 1][x] = true; func(x, y + 1); } if (x + 1 <= w && matrix[y][x + 1] == false && abs(taka - ((int)b[y][x + 1] - 48)) <= 1) { matrix[y][x + 1] = true; func(x + 1, y); } if (x - 1 >= 0 && matrix[y][x - 1] == false && abs(taka - ((int)b[y][x - 1] - 48)) <= 1) { matrix[y][x - 1] = true; func(x - 1, y); } if (y - 2 >= 0 && matrix[y - 2][x] == false && (int)b[y - 1][x]<=taka && taka - ((int)b[y - 2][x] - 48) == 0) { matrix[y - 2][x] = true; func(x, y - 2); } if (y + 2 <= h && matrix[y + 2][x] == false && (int)b[y + 1][x] <= taka && taka - ((int)b[y + 2][x] - 48) == 0) { matrix[y + 2][x] = true; func(x, y + 2); } if (x + 2 <= w && matrix[y][x + 2] == false && (int)b[y][x + 1] <= taka && taka - ((int)b[y][x + 2] - 48) == 0) { matrix[y][x + 2] = true; func(x + 2, y); } if (x - 2 >= 0 && matrix[y][x - 2] == false && (int)b[y][x - 1] <= taka && taka - ((int)b[y][x - 2] - 48) == 0) { matrix[y][x - 2] = true; func(x - 2, y); } return 0; } int main() { cin >> h >> w; //cin >> w >> h; //cin >> sx >> sy >> gx >> gy; cin >> sy >> sx >> gy >> gx; h--; w--; sx--; sy--; gx--; gy--; for (i = 0; i <= h; i++) { //for (i = 0; i <= w; i++) { string st; cin >> st; b.push_back(st); } matrix[sy][sx] = true; //func(sy, sx); func(sx, sy); cout << "NO" << endl; getchar(); getchar(); return 0; }