又RE了,救救孩子
查看原帖
又RE了,救救孩子
107527
chenkaiwen楼主2021/7/26 17:33
#include<bits/stdc++.h>
using namespace std;
int T,x,y,t=0,w=0,ans=0x3f;
bool b[100500]; 
struct as{
	int x,s;
}z[500020],q1,q2;
void push(int x,int s){
	q1.x=x,q1.s=s;
	z[t++]=q1;
}
as top(){
	return z[w++];
}
void In(){
	cin>>x>>y;
}
void Work(){
	memset(b,0,sizeof(b));
	push(x,0);
	b[x]=1;
	while(t-w>0){
		q2=top();
		int u=q2.x,v=q2.s;
		if(u==y){
			ans=min(ans,v);
		}
		if(u+1<=100000){
			if(!b[u+1]){
				b[u+1]=1;
				push(u+1,v+1);
			}
		}
		if(u-1>0){
			if(!b[u-1]){
				b[u-1]=1;
				push(u-1,v+1);
			}
		}
		if(u*2<=100000){
			if(!b[u*2]){
				b[u*2]=1;
				push(u*2,v+1); 
			}
		}
	}
	cout<<ans<<endl;
}
int main(){
	cin>>T;
	while(T--){
		In();
		Work();
	}
	return 0;
}

感觉数据大小已经开够了,但还是RE了

2021/7/26 17:33
加载中...