为什么我的代码会 全 MLE ?
查看原帖
为什么我的代码会 全 MLE ?
930506
Bill_luogu楼主2024/1/25 16:11

各位 dalaodalao ,帮帮 本蒟蒻吧!我真的没办法了

#include<iostream>
#include<queue>
using namespace std;
const int dx[]={0,-1,1};
struct node
{
	int x;
	int step;
};
queue <node> q;
long long n;
bool vis[1];
void bfs()
{
	while(q.size())
	{
		node now=q.front();
		q.pop();
		if(now.x==n)
		{
			cout<<now.step;
			exit(0);
		}
		for(int i=1;i<=3;i++)
		{
			int xx=now.x+dx[i];
			if(xx>=1&&xx<=n&&vis[xx]==0)
			{
				node tool;
				tool.x=xx,tool.step=now.step+1;
				q.push(tool);
			}
		}
		int xx=now.x*2;
		if(xx>=1&&xx<=n&&vis[xx]==0)
		{
			node tool;
			tool.x=xx,tool.step=now.step+1;
			q.push(tool);
		}
	}
}
int main()
{
	cin>>n;
	node tool;
	tool.x=1,tool.step=0;
	vis[1]=1;
	q.push(tool);
 	bfs();
	return 0;
} 
2024/1/25 16:11
加载中...