HDU ACM 2 1175 连连看

来源:互联网 发布:友价商城t5源码 编辑:程序博客网 时间:2024/05/16 18:11

我的代码炸了。就是放着看看

#include <queue>#include <cstdio>#include <algorithm>#include <cmath>#include <iostream>using namespace std;int N, M;int Lu[1005][1005], Hui[1005][1005];typedef pair<int, int> P;int sx, sy, gx, gy;const int INF = 0x3f3f3f3f;int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};int bfs(){queue<P> que;for (int i = 0; i <= N + 1; i++)for (int j = 0; i <= M + 1; j++)Hui[i][j] = INF;que.push(P(sx, sy));Hui[sx][sy] = 0;while (que.size()){P p = que.front(); que.pop();if (p.first == gx && p.second == gy)break;for (int i = 0; i < 4; i++){int nx = p.first + dx[i], ny = p.second + dy[i];if (nx >= 0 && nx <= N + 1 && ny >= 0 && ny <= M + 1 && Lu[nx][ny] == 0 && Hui[nx][ny] == INF){que.push(P(nx, ny));Hui[nx][ny] = Hui[p.first][p.second] + 1;}}}return Hui[gx][gy];}int main(){int n;int x1, x2, y1, y2;while (scanf("%d%d%*c", &N, &M) && (N,M)){for (int i = 1; i <= N; i++)for (int j = 1; j <= M; j++)scanf("%d", &Lu[i][j]);scanf("%d", &n);while (n--){scanf("%d%d%d%d", &x1, &y1, &x2, &y2);if (Lu[x1][y1] == 0 || Lu[x2][y2] == 0){printf("NO\n");continue;}int Min = abs(x1 - x2) + abs(y1 - y2);for (int i = x1 - 1; i <= x2 + 1; i++){Lu[i][y1 -1] = 0;Lu[i][y2 + 1] = 0;}for (int j = y1 - 1; j <= y2 + 1; j++){Lu[x1 - 1][j] = 0;Lu[x2 + 1][j] = 0;}sx = x1;sy = y1;gx = x2;gy = y2;bfs();if (Min == Hui[gx][gy])printf("YES\n");elseprintf("NO\n");}}return 0;}


0 0
原创粉丝点击