为什么会RE,大佬救救我
查看原帖
为什么会RE,大佬救救我
812227
Sunrise_beforeglow楼主2023/10/5 09:08
#include <bits/stdc++.h>
using namespace std;
long long n,tmp,l[200005];
void bfs()
{
	queue <int> q;
	q.push(1);
	l[1]=0;
	while(!q.empty())
	{
		tmp=q.front();
		if(tmp==n)
		{
			cout<<l[n];
			return;
		}
		if(tmp-1>0&&l[tmp-1]==-1)
		{
			q.push(tmp-1);
			l[tmp-1]=l[tmp]+1;
		}
		if(tmp+1<=n&&l[tmp+1]==-1)
		{
			q.push(tmp+1);
			l[tmp+1]=l[tmp]+1;
		}
		if(tmp*2<=n&&l[tmp*2]==-1)
		{
			q.push(tmp*2);
			l[tmp*2]=l[tmp]+1;
		}
		q.pop();
	}
	return;
}
int main()
{
	cin>>n;
	memset(l,-1,sizeof(l));
	bfs();
	return 0;
}

20分,其余RE,求大佬帮忙改正

2023/10/5 09:08
加载中...