zs

yaoyixuan 2023-11-18 9:44:03

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<stdlib.h>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<deque>
using namespace std;
int n,m;
bool dfs(int n){
	if(n==m) return 1;
	if(n==1) return 0;
	if(n%2==0) return dfs(n/2);
	if(n%2==1){
		return (dfs(n-1)||dfs(n+1));
	} 
}
int main(){ 
	cin>>n>>m;
	if(dfs(n)) cout<<"Yes";
	else cout<<"No";
	return 0;
}
~~~···

共 1 条回复

yaoyixuan
int dfs(int n,int cnt){
	if(n==1) return cnt;
	if(n%2==0) return dfs(n/2,cnt+1);
	if(n%2==1){
		return min(dfs(n+1,cnt+1),dfs(n-1,cnt+1));
	} 
}
int main(){ 
	cin>>n;
	cout<<dfs(n,m);
	return 0;
}