1360 奇怪的电梯(lift)
作者:互联网
#include<bits/stdc++.h> using namespace std; struct dt{ int cs,bs; }que[210]; int n,a,b,ans=-1; int yd[205]; int book[205]; int f,r; bool fs=false; void move(int x,int y){ if(x>=0 && x<=200 && book[x]==0){ book[x]=1; r++; que[r].cs=x; que[r].bs=y+1; } } int main(){ memset(book,0,sizeof(book)); cin>>n>>a>>b; for(int i=1;i<=n;i++){ cin>>yd[i]; } f=r=1; que[r].cs=a , que[r].bs=0; while(f<=r){ int nx,nb; nx=que[f].cs,nb=que[f].bs; if(nx==b){ ans=nb; break; } move(nx+yd[nx] , nb); move(nx-yd[nx] , nb); f++; } cout<<ans<<endl; return 0; }
标签:205,int,yd,电梯,lift,que,1360,bs,cs 来源: https://www.cnblogs.com/qwn34/p/13774309.html