求助
查看原帖
求助
1287887
_zhaosihan_qwq_楼主2024/12/29 09:49
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
struct node{
	int now, dis;
};
int n, vis[N],a;
void bfs(int x, int y){
	queue <node> q;
	q.push((node){x, y});
	while (!q.empty()){
		int sx = q.front().now, sy = q.front().dis;
		q.pop();
  		if (sx < 1 || sx > n || vis[sx]) continue;
		vis[sx] = 1;
		if (sx == n){
			cout<<sy;
			return ;
		}
		q.push((node){sx - 1, sy + 1});
		q.push((node){sx + 1, sy + 1});	
		q.push((node){sx+5, sy + 1});	
		q.push((node){sx-5, sy + 1});	
		q.push((node){sx-10, sy + 1});	
		q.push((node){sx+10, sy + 1});

	}
}
int main(){
	cin>>a>>n;
	bfs(a, 0);
	cout<<endl;
	return 0;
}

求助,0分,玄关

2024/12/29 09:49
加载中...