为什么全RE!
查看原帖
为什么全RE!
977653
I_am_a_boy楼主2023/8/23 14:29
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
const int N=2e5+1;
long long n,a,b;
long long vis[N];
int main()
{
	cin>>n;
	while(n--)
	{
		cin>>a>>b;
		queue<long long>q;
		vis[a]=0;
		q.push(a);
		while(!q.empty())
		{
			if(a==b)
			{
				cout<<0;
				return 0;
			}
			long long p=q.front();
			q.pop();
			if(p==b)break;
			if(p+1<=N&&vis[p+1]==vis[0])
			{
				q.push(p+1);
				vis[p+1]=vis[p]+1;
			}
			if(p-1>0&&vis[p-1]==vis[0])
			{
				q.push(p-1);
				vis[p-1]=vis[p]+1;
			}
			if(vis[p*2]==0||2*p<=vis[0])
			{
				q.push(2*p);
				vis[2*p]=vis[p]+1;
			}
		}
		cout<<vis[b];
	}
}
2023/8/23 14:29
加载中...