蓝桥杯其他真题点这里👈
//偶数行需要反转,判断行数时,最后一个需要特判,可以用向上取整
//也可以把传入的值减一,下标从0开始
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;public class Main{static int w,m,n;static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));public static void main(String[] args) throws IOException {String[] init = in.readLine().split(" ");w = Integer.parseInt(init[0]);m = Integer.parseInt(init[1]);n = Integer.parseInt(init[2]);m--;n--;int x1 = m / w; //这么写的话 0 ~ w - 1算一层,所以上面的m和n需要先 - 1int y1 = m % w; //先这么写,下标为0 ~ w - 1正序,通过x1判断是否需要反转int x2 = n / w;int y2 = n % w;if (x1 % 2 == 0) y1 = (w - 1) - y1; //此时反转,下标为0~w-1if (x2 % 2 == 0) y2 = (w - 1) - y2; //0转到 (w - 1) - 0 1 转到 (w - 1) - 1//比如0转到5,1转到4System.out.println(Math.abs(x1 - x2) + Math.abs(y1 - y2));in.close();}
}