Why?
查看原帖
Why?
1127401
JeremyXie楼主2024/1/26 17:23

P1135 奇怪的电梯 神马玩意

#include <bits/stdc++.h>
using namespace std;
int n, a,b,d=0;
int m[205];
//bool vis[205];
void bfs() {
	int t;
    queue<int> q;
    q.push(a);
    while(!q.empty()) {
    		int h=q.front();
    		if(h==b) break;
				q.pop();
        if(h < 1 || h > n) continue;
				q.push(h+m[h]);
				q.push(h-m[h]);
				d++;
    }

}

int main() {
    cin >> n >> a>>b;
    for(int i = 1; i <= n; i++) cin >> m[i];
    bfs();
		cout<<d;
    return 0;
}
2024/1/26 17:23
加载中...