0pts!样例未过!求大佬
查看原帖
0pts!样例未过!求大佬
1016748
Wangyuqi2010楼主2024/2/25 14:51
#include<iostream>
#include<stack>
#include<cstring>
using namespace std;
struct coord {
	int floor,num;
};
coord s[201];
int step[201];
bool flag[201];
stack<coord>q;
int main() {
	memset(flag,true,sizeof(flag));
	int n,a,b;
	cin>>n>>a>>b;
	for(int i=1; i<=n; i++) {
		cin>>s[i].num;
		s[i].floor=i;
	}
	step[a]=0;
	flag[a]=false;
	q.push(s[a]);
	while(!q.empty()) {
		coord now=q.top();
		q.pop();
		int nf=now.floor,nu=now.num;
		//------
		int nf1=nf-nu;
		int nf2=nf+nu;
		if(nf1>1&&flag[nf1]) {
			q.push(s[nf1]);
			step[nf1]=step[nf]++;
			flag[nf]=false;
		}
		if(nf2<n&&flag[nf2]) {
			q.push(s[nf2]);
			step[nf2]=step[nf]++;
			flag[nf]=false;
		}
		else continue; 
	}
	cout<<step[b];
	return 0;
}
2024/2/25 14:51
加载中...