求助啊~~~
  • 板块灌水区
  • 楼主tian_jun_cheng
  • 当前回复2
  • 已保存回复2
  • 发布时间2022/3/9 18:33
  • 上次更新2023/10/28 06:58:19
查看原帖
求助啊~~~
377434
tian_jun_cheng楼主2022/3/9 18:33
#include<bits/stdc++.h>
using namespace std;
int dx[3]={1,-1};
struct node{
	int x,t;
};
queue <node> q;
bool vis[100001];
int n,k;
void bfs(int sx)
{
	int ans=0x3f;
	node h,t;
	t={sx,0};
	q.push(t);
	vis[sx]=true;
	while(!q.empty())
	{
		h=q.front();
		q.pop();
		dx[2]=h.x;
		for(int i=0;i<=2;i++)
		{
			int nx=h.x+dx[i];
			int nt=h.t+1;
			if(nx==k)
				ans=min(ans,nt);
			if(nx>=0 && nx<=100000 && !vis[nx])
			{
				t={nx,nt};
				q.push(t);
				vis[nx]=true;
			}
		}
	}
	cout<<ans;
}
int main()
{
	cin>>n>>k;
	bfs(n);
	return 0;
}

http://ybt.ssoier.cn:8088/problem_show.php?pid=1253

快疯了(我好菜

2022/3/9 18:33
加载中...