#include #include #include #include #define N 1001 using namespace std; int fx[8][2] = { 0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1 }, n, m, sx, sy, ex, ey, tp, tb; struct Map { int cb; int path; int x; int y; char c; friend bool operator<(Map t1, Map t2) { if (t1.cb == t2.cb) { return t1.path>t2.path; } return t1.cb>t2.cb; } }; Map map[N][N]; void input() { int i, j, k; scanf("%d%d%d%d", &sx, &sy, &ex, &ey); for (i = 1; i <= n; i++) { getchar(); for (j = 1; j <= m; j++) { map[i][j].c = getchar(); map[i][j].path = -1; } } } bool isvalide(int x, int y) { if (x<1 || x>n || y<1 || y>m || map[x][y].c == '0') return false; return true; } void BFS() { int i, j, k; priority_queue qu; Map t1, t2; int tx, ty; map[sx][sy].path = 0; map[sx][sy].cb = 0; t1 = map[sx][sy]; t1.x = sx; t1.y = sy; qu.push(t1); while (!qu.empty()) { t2 = qu.top(); if (t2.cb>tb || (t2.cb == tb&&t2.path >= tp)) return; qu.pop(); for (i = 0; i<8; i++) { tx = t2.x + fx[i][0]; ty = t2.y + fx[i][1]; if (isvalide(tx, ty)) { if (map[tx][ty].path != -1) { if (map[tx][ty].c != t2.c) { if (map[tx][ty].cb