#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e5+100;
int mi[N];
int n, m;
queue <int> dl;
int main()
{
rei(n), rei(m);
if (n == m) return puts("0"), 0;
dl.push(n); mi[n] = 0;
while (!dl.empty())
{
int x = dl.front();
dl.pop();
int y = x * 2;
if (y <= 100000)
{
if (!mi[y])
{
mi[y] = mi[x] + 1;
dl.push(y);
}
}
y = x - 1;
if (y > 0)
{
if (!mi[y])
{
mi[y] = mi[x] + 1;
dl.push(y);
}
}
}
printf("%d\n", mi[m]);
return 0;
}
04-30
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交