社区讨论
第二个点RE 90pts求助
P3818小A和uim之大逃离 II参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mhjt5xo7
- 此快照首次捕获于
- 2025/11/04 08:05 4 个月前
- 此快照最后确认于
- 2025/11/04 08:05 4 个月前
CPP
#include <bits/stdc++.h>
using namespace std;
int h, w, d, r, a[1010][1010], v[1010][1010][2], ans = INT_MAX;
struct state {
int x, y, u, s;
};
queue<state> q;
string s;
void push(int x, int y, int u, int s) {
if (!a[x][y] || v[x][y][u] || x < 1 || x > h || y < 1 || y > w)
return;
q.push(state{x, y, u, s});
v[x][y][u] = true;
if (x == h && y == w)
ans = min(ans, s);
}
int main() {
cin >> h >> w >> d >> r;
for (int i = 1; i <= h; i++) {
cin >> s;
for (int j = 1; j <= w; j++)
if (s[j - 1] == '.')
a[i][j] = true;
}
push(1, 1, 0, 0);
while (!q.empty()) {
int x = q.front().x, y = q.front().y, u = q.front().u, s = q.front().s;
q.pop();
if (u == 0)
push(x + d, y + r, 1, s + 1);
push(x + 1, y, u, s + 1);
push(x - 1, y, u, s + 1);
push(x, y + 1, u, s + 1);
push(x, y - 1, u, s + 1);
}
if (ans == INT_MAX)
cout << "-1\n";
else
cout << ans << endl;
return 0;
}
见https://www.luogu.com.cn/record/216294236
回复
共 2 条回复,欢迎继续交流。
正在加载回复...