算红线的步数
代码:
Scanner scan = new Scanner(System.in);
long x = scan.nextLong();
long y = scan.nextLong();
scan.close();
long max = Math.max(Math.abs(x),Math.abs(y));
long res = 0;
if( x == max){
res = x*(4*x+1)-y;
}else if (x == -max){
res = max*(4*max-3)+y;
}else if( y == max){
res = y*(4*y-1)+x;
}else{
res = max*(4*max+3)-x;
}
System.out.print(res);
记住公式即可套用。