@[蒟蒻chi_chi](/space/show?uid=31728) 您是怎么停止工作的
by 单曦增 @ 2018-05-26 13:55:56
您的n,a,b根本就没输入好吧
by 单曦增 @ 2018-05-26 13:57:18
@[单曦增](/space/show?uid=53250) 哦哦哦,我傻了。。。。我去改改、
by si_zhong @ 2018-05-26 13:58:21
@[单曦增](/space/show?uid=53250)
```cpp
#include <bits/stdc++.h>
using namespace std;
int n,a,b,h=1,t=1;
int main() {
struct U {
int f;
int can;
int s;
};
U k[209];
U q[209];
cin>>n>>a>>b;
for(int i=1; i<=n; i++) cin>>k[i].can,k[i].f=i,k[i].s=1;
q[++t]=k[a];
do {
if(q[h].f+q[h].can==b||q[h].f-q[h].can==b) {
cout<<q[h].s+1;
return 0;
}
if(q[h].f+q[h].can>0) {
q[++t].f=q[h].f+q[h].can;
q[t-1].s=q[h].s+1;
q[t-1].can=k[q[t-1].f].can;
}
if(q[h].f-q[h].can<=n) {
q[++t].f=q[h].f-q[h].can;
q[t-1].s=q[h].s+1;
q[t-1].can=k[q[t-1].f].can;
}
h++;
} while(h+1!=t);
cout<<"-1";
return 0;
}
```
# 输入了之后还是停止工作啊!
by si_zhong @ 2018-05-26 14:00:53
结构体和数组定义在main里面......
by Zenurik @ 2018-05-26 14:03:18
@[蒟蒻chi_chi](/space/show?uid=31728)
by Zenurik @ 2018-05-26 14:03:59
@[蒟蒻chi_chi](/space/show?uid=31728) 首先,您的程序里q[h].f+q[h].can没有保证小于等于n,q[h].f-q[h].can也没有保证大于0
by 单曦增 @ 2018-05-26 14:07:59
@[Zenurik](/space/show?uid=47996) 哦哦,今天可能天气不大好,脑子坏了。
by si_zhong @ 2018-05-26 14:08:10
还有,您那里为什么要写t-1?不就是t吗
by 单曦增 @ 2018-05-26 14:08:55
@[单曦增](/space/show?uid=53250) 有的啊,我写了if语句的。
by si_zhong @ 2018-05-26 14:09:13