ac

蛋仔6神  •  24天前


假的,是错的111111111111111111111111111111111111111111111111111111111111111111111111111111111

include<bits/stdc++.h>

using namespace std; int n,a,b,k[205],bj[205],c[3]; struct wz{

int x,y;

}; void bfs(int x){

queue<wz> q;
q.push({x,0});
while(q.size()!=0){
	wz tou=q.front();
	q.pop();
	c[1]=tou.x+k[tou.x],c[2]=tou.x-k[tou.x];
	for(int i=1;i<=2;i++){
		if(c[i]<=n&&c[i]>=1&&bj[c[i]]==0){
			bj[c[i]]=1;
			if(c[i]==b){
				cout<<tou.y+1;return ;
			}
			else{
				q.push({c[i],tou.y+1});
			}
		}
	}
}
cout<<-1;

} int main(){

cin>>n>>a>>b;
for(int i=1;i<=n;i++){
	cin>>k[i];
}
if(a==b){
	cout<<0;
	return 0;
}
bfs(a);
return 0;

}


评论:

要看就看,错了别怪我,嘻嘻


蛋仔6神  •  24天前

啊哈哈哈哈哈哈哈哈哈


蛋仔6神  •  24天前

请先登录,才能进行评论