50分(wa5个点),求神犇调
查看原帖
50分(wa5个点),求神犇调
553255
遇事不决就选C楼主2022/10/31 09:02
#include<bits/stdc++.h>
using namespace std;
int n, m, t, sx, sy, fx, fy, ans, dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
bool a[10][10], ma[10][10];
struct maps {
	int x, y;
};
void bfs() {
	queue<maps>q;
	q.push({sx, sy});
	a[sx][sy] = 1;
	while (!q.empty()) {
		maps Ma = q.front();
		int nx = Ma.x, ny = Ma.y;
		q.pop();
		if (nx == fx && ny == fy) {
			ans++;
			continue;
		}
		a[nx][ny] = 1;
		for (int i = 0; i < 4; i++) {
			int nnx = nx + dx[i], nny = ny + dy[i];
			if (a[nnx][nny] || ma[nnx][nny] || nnx < 1 || nnx > n || nny < 1 || nny > m) continue;
			q.push({nnx, nny});
		}
	}
}
int main(){
	cin >> n >> m >> t >> sx >> sy >> fx >> fy;
	int x, y;
	for (int i = 0; i < t; i++) {
		cin >> x >> y;
		ma[x][y] = 1;
	}
	bfs();
	cout << ans;
	return 0;
}

2022/10/31 09:02
加载中...