文章
40
粉丝
512
获赞
13
访问
372.9k
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
struct status{
int n,t;
status(int x,int y):n(x),t(y){}
};
bool visit[201];
int N,A,B;
int arr[201];
int BFS(int a,int b){
queue<status> mq;
mq.push(status(a,0));
visit[a]=true;
while(!mq.empty()){
status current = mq.front();
mq.pop();
if(current.n==b){
return current.t;
}
for(int i=0;i<2;i++){
status next(current.n,current.t+1);
if(i==0){
next.n -= arr[next.n];
}else{
next.n += arr[next.n];
}
if(next.n<1||next.n>N||visit[next.n]){
continue;
}
mq.push(next);
visit[next.n]=true;
}
}
return -1;
}
int main(){
cin>>N>>A>>B;
for(int i=1;i<=N;i++){
cin>>arr[i];
...
登录后发布评论
暂无评论,来抢沙发