七彩求助,玄关
  • 板块P1605 迷宫
  • 楼主残阳如血
  • 当前回复5
  • 已保存回复5
  • 发布时间2023/7/20 20:46
  • 上次更新2023/11/3 08:34:17
查看原帖
七彩求助,玄关
726139
残阳如血楼主2023/7/20 20:46

彩虹

#include <bits/stdc++.h>
using namespace std;
const int dir[][2] = {0, 1, 1, 0, 0, -1, -1, 0};
struct point {
	int x, y;
	friend bool operator < (point a, point b) {
		if (a.x == b.x) return a.y < b.y;
		else return a.x < b.y;
	}
};
int N, M, T, ans, sx, sy, ex, ey;
int vis[10][10];
void dfs(point cur) {
	vis[cur.x][cur.y] = 1;
	if (cur.x == ex && cur.y == ey) {
		ans++;
		return ;
	}
	for (int i = 0; i < 4; i++) {
		int fx = cur.x + dir[i][0];
		int fy = cur.y + dir[i][1];
		if (fx < 1 || fy > N || fy < 1 || fy > M) continue;
		if (vis[fx][fy] == -1 || vis[fx][fy] == 1) continue;
		dfs({fx, fy});
	}
	return ;
}
int main() {
	cin >> N >> M >> T >> sx >> sy >> ex >> ey;
	while (T--) {
		int x, y;
		cin >> x >> y;
		vis[x][y] = -1;
	}
	if (vis[N][M] == -1) {
		cout << 0;
		return 0;
	}
	dfs({sx, sy});
	cout << ans;
	return 0;
}

求助!玄关

2023/7/20 20:46
加载中...