社区讨论
10tps,玄1关
P1238走迷宫参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mkl80v4k
- 此快照首次捕获于
- 2026/01/19 21:48 上个月
- 此快照最后确认于
- 2026/01/20 09:18 4 周前
CPP
#include <bits/stdc++.h>
#define re register
#define int long long
#define cout(i) putchar_unlocked(i)
using namespace std;
int n, m;
vector<vector<int> > p(18, vector<int>(18));
vector<pair<int, int> > a;
bool flag[15][15] = {false}, Go = true;
int Go_x, Go_y, St_x, St_y;
inline int read() {
int x = 0, f = 1;
char ch = getchar_unlocked();
while (ch != '-' && (ch < '0' || ch > '9')){
ch = getchar_unlocked();
}
if (ch == '-') {
f = -1;
ch = getchar_unlocked();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar_unlocked();
}
return x * f;
}
inline void write(int x) {
if (x < 0) putchar_unlocked('-'), x = abs(x);
if (x > 9) write(x / 10);
putchar_unlocked(x % 10 + '0');
}
void Out_ans() {
Go = false;
cout('(');cout(a[0].first + '0');cout(',');cout(a[0].second + '0');cout(')');
for (size_t i = 1; i < a.size(); i++) {
cout('-');cout('>');
cout('(');cout(a[i].first + '0');cout(',');cout(a[i].second + '0');cout(')');
}
cout('\n');
}
void dfs(int i, int j) {
if (i < 1 || i > m || j < 1 || j > n || p[i][j] == 0 || flag[i][j]) return;
if (i == St_x && j == St_y) {
a.push_back({i, j});
Out_ans();
a.pop_back();
return;
}
flag[i][j] = true;
a.push_back({i, j});
dfs(i - 1, j);
dfs(i, j - 1);
dfs(i + 1, j);
dfs(i, j + 1);
a.pop_back();
flag[i][j] = false;
}
signed main() {
m = read(), n = read();
for (re int i = 1; i <= m; i++) for (re int j = 1; j <= n; j++) p[i][j] = read();
Go_x = read(), Go_y = read(), St_x = read(), St_y = read();
if (Go_x == St_x && Go_y == St_y) {
cout('(');cout(Go_x + '0');cout(',');cout(Go_y + '0');cout(')');
cout('\n');
Go = false;
} else {
dfs(Go_x, Go_y);
}
if (Go) write(-1);
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...