社区讨论
10pst求调必关
P1238走迷宫参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mjcrfhyw
- 此快照首次捕获于
- 2025/12/19 19:02 2 个月前
- 此快照最后确认于
- 2025/12/21 11:15 2 个月前
CPP
#include<iostream>
using namespace std;
const int N = 18;
int m, n, X[4] = {1, 0, 1, 0}, Y[4] = {0, -1, 0, 1}, x_0, y_0, x_m, y_n, ans[N * N][3];
bool mp[N][N], vis[N][N], win = 0;
void DFS(int x, int y, int cnt) {
if (x < 1 || y < 1 || x > m || y > n || !mp[x][y] || vis[x][y])return;
if (x == x_m && y == y_n) {
for (int i = 1; i <= cnt; i++) {
cout << '(' << ans[i][1] << ',' << ans[i][2] << ')';
if (i != cnt)cout << "->";
}
cout << '\n';
win = 1;
return;
}
vis[x][y] = 1;
ans[cnt][1] = x, ans[cnt][2] = y;
for (int i = 0; i < 4; i++) {
DFS(x + X[i], y + Y[i], cnt + 1);
}
vis[x][y] = 0;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr), cout.tie(nullptr);
cin >> m >> n;
for (int i = 1; i <= m; i++)for (int j = 1; j <= n; j++)cin >> mp[i][j];
cin >> x_0 >> y_0 >> x_m >> y_n;
DFS(x_0, y_0, 1);
if (!win)cout << "-1\n";
return 0;
}
重复输出qwq
回复
共 1 条回复,欢迎继续交流。
正在加载回复...