标签:oid push include struct ++ bre front int div
#include<bits/stdc++.h> using namespace std; struct { int p,step; } q[250]; int front,rear; bool b[250]; int n,x,y,k[250]; void push(int x,int s) { q[rear].p=x; q[rear].step=s; rear++; b[x]=true; } int main() { cin>>n>>x>>y; for(int i=1;i<=n;++i) cin>>k[i]; if(x==y) cout<<0; else { push(x,0); while(front!=rear) { int t=q[front].p; if(t+k[t]<=n&&!b[t+k[t]]) { push(t+k[t],q[front].step+1); if(t+k[t]==y) break; } if(t-k[t]>0&&!b[t-k[t]]) { push(t-k[t],q[front].step+1); if(t-k[t]==y) break; } front++; } if(front!=rear) cout<<q[rear-1].step; else cout<<-1; } }
标签:oid push include struct ++ bre front int div
原文地址:https://www.cnblogs.com/ghost79/p/12241933.html