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

#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

相关推荐

07-17 12:14
门头沟学院 Java
点赞 评论 收藏
分享
05-30 12:03
山西大学 C++
offer来了我跪着...:不是骗子,等到测评那一步就知道为啥这么高工资了
点赞 评论 收藏
分享
Java大菜狗:纯纯招黑奴,一天还不到两百那么多要求,还不迟到早退,以为啥啊,给一点工资做一堆活,还以不拖欠员工工资为荣,这是什么值得骄傲的事情吗,纯纯***公司
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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