一圈一个区域划分,用x y的最大值判断在哪个圈,最后分四个方向分别判断
import java.util.*;
import java.io.*;
public class Main {
static class Input {
StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
public int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
}
public static void main(String[] args) throws IOException {
Input in = new Input();
int x = in.nextInt(),y = in.nextInt();
long n = Math.max(Math.abs(x),Math.abs(y));
long res = 4 * (n - 1) * n;
if(x == -n) {
if(y == -n) {
res += (8 * n);
} else {
res += (n + y);
}
} else if(y == n) {
res += (2 * n) + (n + x);
} else if(x == n) {
res += (4 * n) + (n - y);
} else if(y == -n) {
res += (6 * n) + (n - x);
}
System.out.println(res);
}
}