90分求助,不知道哪错了
查看原帖
90分求助,不知道哪错了
653212
shensiyuan2011楼主2023/4/9 21:35
#include <bits/stdc++.h>
using namespace std;

struct dxy {
	int x, y;
};
dxy d[5];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	d[0].x = 0, d[0].y = 0, d[1].x = -1, d[1].y = 0, d[2].x = 0, d[2].y = -1, d[3].x = 1, d[3].y = 0, d[4].x = 0,
	    d[4].y = 1;
	int n, m, x, y, t, l, r, sx, sy, fx, fy, ans = 0;
	bool a[7][7] = {0}, uw[2540][7][7] = {0};
	int qu[2][2550];
	cin >> n >> m >> t >> sx >> sy >> fx >> fy;
	for (int i = 0; i < t; i++) {
		cin >> x >> y;
		a[x][y] = 1;
	}
	l = 1, r = 1;
	qu[0][1] = sx;
	qu[1][1] = sy;
	uw[1][sx][sy] = 1;
	while (l <= r) {
		for (int i = 1; i <= 4; i++) {
			int xx = qu[0][l] + d[i].x, yy = qu[1][l] + d[i].y;
			if (uw[l][xx][yy] == 1 || a[xx][yy] == 1 || xx == 0 || yy == 0 || xx > n || yy > m)
				continue;
			if (xx == fx && yy == fy) {
				++ans;
				continue;
			}
			r++;
			qu[0][r] = xx;
			qu[1][r] = yy;
			memcpy(uw[r], uw[l], sizeof(uw[l]));
			uw[r][xx][yy] = 1;
		}
		l++;
	}
	cout << ans;
	return 0;
}

测试点8wa
输入:
5 5 0
1 1 2 2
标准输出:
4846
我的输出:
123
帮忙看看

2023/4/9 21:35
加载中...