第四个点卡住了,求为什么

P1135 奇怪的电梯

@[luoru_0221](/space/show?uid=169931) 我也不知道发生了什么我猜测应该是读入了一些多余的东西吧main函数里改了一下 ```cpp #include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; int F[201],res[201]; int n,tmp; int fun(int a,int b) { memset(res,-1,sizeof(res)); queue<int> q; q.push(a); res[a]=0; while(!q.empty()) { tmp=q.front(); q.pop(); if(tmp+F[tmp]>0&&tmp+F[tmp]<=n&&res[tmp+F[tmp]]==-1) { res[tmp+F[tmp]]=res[tmp]+1; q.push(tmp+F[tmp]); } if(tmp-F[tmp]>0&&tmp-F[tmp]<=n&&res[tmp-F[tmp]]==-1) { res[tmp-F[tmp]]=res[tmp]+1; q.push(tmp-F[tmp]); } } return res[b]; } int main() { int a,b; scanf("%d %d %d",&n,&a,&b); for(int i=1;i<=n;i++)scanf("%d",&F[i]); printf("%d\n",fun(a,b)); return 0; } ``` AC
by oh_yes @ 2019-02-21 15:33:18


|