解题思路:
注意:
1.静态方法只能访问静态变量
static int[] x = new int[] { -2, -1, 1, 2, 1, -1 };
static int[] y = new int[] { 0, 1, 1, 0, -1, -1 };
或者
static int[] x = { -2, -1, 1, 2, 1, -1 };
static int[] y = { 0, 1, 1, 0, -1, -1 };
都可以
2.并且在Java中,static变量不能在方法内部声明,它们必须作为类的成员变量声明。
import java.util.Scanner;
public class Main {
static int[] x = new int[] { -2, -1, 1, 2, 1, -1 };
static int[] y = new int[] { 0, 1, 1, 0, -1, -1 };
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int d1 = scan.nextInt();
long p1 = scan.nextLong();
long q1 = scan.nextLong();
int d2 = scan.nextInt();
long p2 = scan.nextLong();
long q2 = scan.nextLong();
long[] pos1 = new long[2];
long[] pos2 = new long[2];
getPositon(d1, p1, q1, pos1);
getPositon(d2, p2, q2, pos2);
System.out.print(getWay(pos1, pos2));
}
public static void getPositon(int d, long p, long q, long[] pos) {
pos[0] = p * x[d] + q * x[(d + 2) % 6];
pos[1] = p * y[d] + q * y[(d + 2) % 6];
}
public static long getWay(long[] pos1, long[] pos2) {
long dx = Math.abs(pos1[0] - pos2[0]);
long dy = Math.abs(pos1[1] - pos2[1]);
if (dx >= dy) return (dx + dy) / 2;
else return dy;
}
}