评测记录(已吸氧)https://www.luogu.com.cn/record/142096618
#include<bits/stdc++.h>
using namespace std;
//const int N = 1000 + 5;
const int M = 1000000 + 5;
int d[M], step[M];
bool vis[M];
int main(){
int head, tail;
int x, y;
cin >> y;
x=1;
head = 0;
tail = 0;
d[head] = x;
step[x] = 0;
vis[x] = 1;
while (head <= tail){
int u = d[head];
// cout << u << endl;
int su = step[u];
int v;
// if (vis[v] == 0 && v < 2 * y) {
// d[++tail] = v;
// vis[v] = 1;
// step[v] = step[u] + 1;
// if (v == y) {
// cout << step[v] << endl;
// break;
// }
// }
// v = u + 1;
// if (vis[v] == 0 && v <= y) {
// d[++tail] = v;
// vis[v] = 1;
// step[v] = step[u] + 1;
// if (v == y) {
// cout << step[v] << endl;
// break;
// }
// }
// v = u - 1;
// if (vis[v] == 0 && v >= 0) {
// d[++tail] = v;
// vis[v] = 1;
// step[v] = step[u] + 1;
// if (v == y) {
// cout << step[v] << endl;
// break;
// }
// }
for (int i = -1; i <= 1; ++i) {
if (i == 0) v = 2 * u;
else v = u + i;
if (vis[v] == 0 && v >= 0 && v <= 2 * 100000) {
d[++tail] = v;
vis[v] = 1;
step[v] = step[u] + 1;
if (v == y) {
cout << step[v] << endl;
return 0;
}
}
}
head++;
}
return 0;
}