bfs64tps蒟蒻求助(C++)
查看原帖
bfs64tps蒟蒻求助(C++)
1144555
gdfz02sjy楼主2024/6/6 16:57
#include<bits/stdc++.h> 
using namespace std;
long long a,f,e,cs=-1;
int b[205][2];//创建数组
void check(int x,int y){
	if(x==e){
		cs=y;
		return ;
	}
	if(cs!=-1||b[x][1]==1||x<=0)return ;
	b[x][1]=1;
	check(x+b[x][0],y+1);
	check(x-b[x][0],y+1);
}
int main(){
	cin>>a>>f>>e;//输入,(first)和(end) 
	for(int i=1;i<=a;i++){
		cin>>b[i][0];
		b[i][1]=0;//初始化 
	}
	check(f,0);
	cout<<cs;
}

有些非主流,#1~#3、#5、#14、#15错了

2024/6/6 16:57
加载中...