标签:namespace i++ space main ret php ring div sizeof
题面 http://ybt.ssoier.cn:8088/problem_show.php?pid=1360
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int q[32768],k[32768],a[32768]; bool b[32768]; int main() { memset(b,0,sizeof(b)); int x,y,n; scanf("%d%d%d",&n,&x,&y); for(int i=1;i<=n;i++) scanf("%d",&k[i]); q[1]=x; b[x]=1; int h=0,t=1; do { h++; for(int i=-1;i<=1;i++) { if((q[h]+k[q[h]]*i>0&&q[h]+k[q[h]]*i<=n)&&!b[q[h]+k[q[h]]*i]) { t++; q[t]=q[h]+k[q[h]]*i; b[q[h]+k[q[h]]*i]=1; a[t]=a[h]+1; } } }while(h!=t&&q[h]!=y); if(x==y)cout<<"0"<<endl; else if(q[h]==y)cout<<a[h]<<endl; else cout<<"-1"<<endl; return 0; }
标签:namespace i++ space main ret php ring div sizeof
原文地址:https://www.cnblogs.com/xrj1229/p/9201308.html