package lanqiaobei;
import java.util.*;
/*
习题:一维坐标的移动
1. 在一个长度为n的坐标轴上,蒜头君想从A点 移动到B点。他的移动规则如下:
2. 向前一步,坐标增加1。
3. 向后一步,坐标减少1。
4. 跳跃一步,使得坐标乘2。
蒜头君不能移动到坐标小于0或大于n的位置。蒜头想知道从A点移动到B点的最少步数是多少,你能帮他计算出来么?
输入格式
第一行输入三个整数n,A,B,分别代表坐标轴长度,起始点坐标,终点坐标。(0≤A,B≤n≤50000)
输出格式
输出一个整数占一行,代表蒜头要走的最少步数。
样例输入
10 2 7
样例输出
3
*/
public class OneZuoBiao {
public static int[] juge = {1, -1, 2};
public static int ress = 0;
public void bfs(int n, int A, int B) {
int[] res = new int[5000];
List<Integer> used = new ArrayList<>();
Queue<Integer> q = new LinkedList();
((LinkedList) q).add(A);
//一层一层向下进行
while (!q.isEmpty()) {
//获得队头元素
int na = q.poll();
//进退跳的三步操作
for (int i = 0; i < juge.length; i++) {
//获得操作完的大小
int m = na + juge[i];
if (m >= 0 && m <= n) {
//跳出条件
if (m == B) {
ress = res[na]+1;
return;
} else {
if (!used.contains(m)) {
used.add(m);
res[m] = res[na] + 1;
((LinkedList<Integer>) q).add(m);
}
}
}
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int A = sc.nextInt();
int B = sc.nextInt();
OneZuoBiao a = new OneZuoBiao();
a.bfs(n, A, B);
System.out.println(ress);
}
}