广搜求助!
  • 板块学术版
  • 楼主poor_OIer
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/7/18 22:52
  • 上次更新2024/7/19 08:50:09
查看原帖
广搜求助!
704634
poor_OIer楼主2024/7/18 22:52

样例都没过

#include<bits/stdc++.h>
using namespace std;
int a,b;
int d[6]={1,-1,5,-5,10,-10};
void bfs(int x)
{
	queue<pair<int,int> > q;
	q.push(make_pair(x,0));
	while(!q.empty())
	{
		for(int i=0;i<6;i++)
		{
			int nx=q.front().first+d[i];
			q.push(make_pair(nx,q.front().second+1));
			if(nx==b)
			{
				cout<<q.front().second;
				return;
			}
		}
		q.pop();
	}
}
int main()
{
	cin>>a>>b;
	if(a==b)
	{
		cout<<0;
		return 0;
	}
	bfs(a);
	return 0;
}
2024/7/18 22:52
加载中...