社区讨论
0pts求调
P1135奇怪的电梯参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mlhsx7yg
- 此快照首次捕获于
- 2026/02/11 17:02 上周
- 此快照最后确认于
- 2026/02/13 14:15 6 天前
CPP
#include <bits/stdc++.h>
using namespace std;
int n, a1, b1;
int a[1000000];
int vis[1000000];
struct node {
int e;
int sum;
};
int main() {
cin >> n >> a1 >> b1;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
queue<node>q;
bool woshishabi;
q.push({a1, 0});
while (!q.empty()) {
node t = q.front();
cout << t.e << " " << t.sum << endl;
q.pop();
if (t.e == b1) {
cout << t.sum;
//cout << "woshidashabi";
woshishabi = 1;
return 0;
}
if (t.e+a[t.e] <= b1 && vis[t.e+a[t.e]] == 0) {
vis[t.e+a[t.e]] = 1;
q.push ({t.e+a[t.e], t.sum + 1});
}
if (t.e-a[t.e] > 0 && vis[t.e-a[t.e]] == 0) {
vis[t.e-a[t.e]] = 1;
q.push ({t.e+a[t.e], t.sum + 1});
}
}
cout << 0;
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...