RE玄关
查看原帖
RE玄关
1097314
封禁用户楼主2024/6/18 20:31

不知道哪错了qwq……

#include<bits/stdc++.h>
using namespace std;
int T,x,y,ans;
int minn(int x,int y,int z){
	return min(x,min(y,z));
}
void dfs(int pos,int tar,int step){
	if(pos==tar){
		ans=min(ans,step);
		return;
	}
	dfs(pos-1,tar,step+1);
	dfs(pos+1,tar,step+1);
	dfs(pos*2,tar,step+1);
}
int main(){
	cin>>T;
	while(T--){
		cin>>x>>y;
		if(x>=y){
			cout<<x-y<<endl;
			continue;
		}
		ans=1e9;
		dfs(x,y,0);
		cout<<ans<<endl;
	}
}
2024/6/18 20:31
加载中...