有大佬帮本蒟蒻看看,这个程序为何段错误吗

#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
typedef long long LL;
const LL N = 1500005;
LL v[5]={-1,1,0,0,0};
LL visit[N+10]={0};
LL Binary(int x)
{
	LL cnt = 0;
	while(1)
	{
		if(x%2==1) cnt++;
		if(x/2==0) return cnt;
		x/=2;
	}
}
struct Step
{
	LL num;
	LL steps;
};

queue<Step> q;

int bfs(int a,int b)
{
	q.push(Step{a,0});
	while(!q.empty())
	{
		Step s = q.front();
		q.pop();
		cout<<"s.num = "<<s.num<<endl;
		LL cnt = Binary(s.num);
		v[2] = cnt;
		v[3] = -cnt;
		if(s.num==b)
		{
			return s.steps;
		}
		for(int i=0;i<4;i++)
		{
			Step next ;
			next.num = s.num + v[i];
			next.steps = s.steps + 1;
			if(next.num<0||next.num>b) continue;
			if(visit[next.num]==1) continue;
			q.push(next);
			visit[next.num] = 1;
		}
	}
}
int main()
{
	memset(visit,0,sizeof(visit));
	int a,b;
	cin>>a>>b;
	visit[a] = 1;
	LL ans = bfs(a,b);
	cout<<ans<<endl;
	return 0;
 } 


全部评论
太复杂了,蒟蒻不会
点赞 回复 分享
发布于 2020-04-05 18:33

相关推荐

牛客20485985...:抱抱😘,首先你还有春招,然后就算这时候没上岸也没关系,大部分人都是这样,毕业了再找也成,最后工作只是生活的一小部分,找到工作也不是一个必须的事情。不要气馁不要焦虑你只是陷入了短暂的低谷,你也一直有退路
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务