萌新求教,为啥输出总是不对呢
查看原帖
萌新求教,为啥输出总是不对呢
489506
LiXingWang楼主2021/3/26 11:21
# include <iostream>
# include <queue>
using namespace std;
int a,b;
int aa[8] = {1,-1,5,-5,10,-10};
struct node{
	int x,y;
};
queue<node> q;
void bfs(node now)
{
	q.push(now);
	while(!q.empty())
	{
		node t = q.front();
		q.pop();
		if(t.x == b)
		{
			cout<<t.y<<endl;
			return ;
		}
		for(int i = 0;i<6;i++)
		{
			int p= t.x+aa[i];
			t.y++;
			node s;
			s.x = p;
			s.y = t.y;
			q.push(s);
		}
	}
}
int main ()
{
	cin>>a>>b;
	node now;
	now.x = a;
	now.y = 0;
	bfs(now);
 } 
2021/3/26 11:21
加载中...