求助
  • 板块P1605 迷宫
  • 楼主jiang_yitao
  • 当前回复2
  • 已保存回复3
  • 发布时间2024/8/20 20:12
  • 上次更新2024/8/20 22:33:22
查看原帖
求助
1276571
jiang_yitao楼主2024/8/20 20:12

在本地能过,但洛谷却编译失败?

#include <bits/stdc++.h>
using namespace std;
int n , m , k , x1 , y1 , x2 , y2 , v[10005][10005] , ans = 0;
int dx[] = {0 , 0 , 1 , -1};
int dy[] = {1 , -1 , 0 , 0};
struct node {
	int x , y , cnt;
	node(int xx , int yy , int cnt1):x(xx) , y(yy) , cnt(cnt1) {}
};
int bfs(int,int);
int bfs(int q , int w) {
	queue<node>a;
	a.push(node(q , w , 0));
	v[q][w] = 1;
	while(!a.empty()) {
		node cur = a.front();
		a.pop();
		for (int i = 0 ; i < 4 ; i ++) {
			int _x  = cur.x + dx[i];
			int _y  = cur.y + dy[i];
			if (_x == n && _y == m) {
				ans ++;
				continue;
			}
			if (_x > 0 && _y > 0 && _x <= n && _y <= m && v[_x][_y] == -1) {
				a.push(node(_x , _y , cur.cnt + 1));
				v[_x][_y] = 1;
			}
		}
	}
	return 0;
}
int main() {
	cin >> n >> m >> k >> x1 >> y1 >> x2 >> y2;
	for (int i = 1 ; i <= n ; i ++)
		for (int j = 1 ; j <=m ; j ++)
			v[i][j] = -1;
	while (k --) {
		int g , h;
		cin >> g >> h;
		v[g][h] = 1;
	}
	bfs(x1 , y1);
	cout << ans << endl;
	return 0;
}
2024/8/20 20:12
加载中...