#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int n,a,b;
int ans[210];
int ok[210]={0};
int bfs(int x)//x为当前楼层
{
queue<int> q;
q.push(x);
while(!q.empty()){
x=q.front();
int c=ans[x];//可以上下的层数
q.pop();
if(x+c==b||x-c==b)return ok[x]+1;
if(x+c<=n&&ok[x+c]==0)//可以走
{
q.push(x+c);
ok[x+c]=ok[x]+1;
}
if(x-c>=1&&ok[x-c]==0){
q.push(x-c);
ok[x-c]=ok[x]+1;
}
}
return -1;
}
int main()
{
scanf("%d%d%d",&n,&a,&b);
for(int i=1;i<=n;i++)
scanf("%d",&ans[i]);
ok[a]=0;
if(a==b)cout<<"0";
else cout<<bfs(a);
return 0;
}
P1135 奇怪的电梯
最新推荐文章于 2024-05-17 09:56:31 发布