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

#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

相关推荐

10-16 19:16
Java
点赞 评论 收藏
分享
10-10 11:38
已编辑
湖南理工大学 Java
小浪_Coding:多沟通叭, 公式简历+学历一般的话难找
点赞 评论 收藏
分享
09-03 17:49
已编辑
四川大学 供应链管理
迷茫的大四🐶:提前实习有些坑的,卡毕业后薪资以及能力不达预期提前违约这种
我的OC时间线
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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