【思路】
做完才发现其实可以预处理 都减去1 哭了
一堆边界判断
import java.util.Scanner;
import java.lang.Math;
class Main{
public static int get_y(int row, int w, int x){
//根据规律 行数为偶数则从左到右递增
int y = 0;
if( (row & 1) == 0 ) y = (x % w == 0? w:x % w);
else y = w - x % w + 1;
return y;
}
public static void main(String args[]){
Scanner reader = new Scanner(System.in);
int w = reader.nextInt(), m = reader.nextInt(), n = reader.nextInt();
//注意处理边界
//计算两个数的位置
int x1 = m / w + (m % w == 0? -1: 0), x2 = n / w + (n % w == 0? -1: 0);
int y1 = get_y(x1, w, m), y2 = get_y(x2, w, n);
//System.out.println(x1+" "+y1);
//System.out.println(x2+" "+y2);
//计算移动距离
int res = Math.abs(x1 - x2) + Math.abs(y1 - y2);
System.out.println(res);
}
}