// catch that cow #include<iostream> usingnamespace std;
constint N = 1e7+10;
int n, k, x; int q[N], v[N], dis[N];
intmain(){ cin >> n >> k; if (n > k) {cout << n-k; return0;} int s = 0, t = 1; q[1] = n, v[n] = 1; while (s <= t) { ++ s; for (int i = 1; i <= 3; ++ i) { int x = q[s]; if (i == 1) ++ x; if (i == 2) -- x; if (i == 3) x<<=1; if (x >= 0 && x <= 100000) if (!v[x]) { v[x] = 1; q[++ t] = x; dis[x] = dis[q[s]] + 1; } } } cout << dis[k]; return0; }
PS:
1.before today I break for two days;
2.It is a very easy bfs.
The only season why I cann't solve this problem is I was very
sily