螺旋队列_#define

#include<cstdio>
#include<iostream>
using namespace std;
#define abs(a) ((a)>0?(a):-(a))
#define max(a,b) ((a)<(b)?(b):(a))
int foo(int x,int y){
if(x==0&&y==0) return 1;
int t=max(abs(x),abs(y));
int t1=((t-1)*2+1)*((t-1)*2+1);
int t2=((t)*2+1)*((t)*2+1);
// printf("t1=%d,t2=%d\n",t1,t2);
if(x+y>0&&x>=y) return t1+x+y;
if(x+y>=0&&x<y) return t1-x-y+4*t;
if(x+y<=0&&x>=y) return t2+x+y;
if(x+y<0&&x<y) return t2-x-y-4*t;
return 0;
}
//第二种 按坐标轴上的数为基准
int foo2(int x,int y){
int t=max(abs(x),abs(y));
int u=t+t;
int v=u-1;
v=v*v;
int v1=v+t;
int v2=v1+2*t;
int v3=v2+2*t;
int v4=v3+2*t;
if(y==-t) return v4+x;
else if(y==t) return v2-x;
else if(x==-t) return v3-y;
else if(x==t) return v1+y;
}
int main()
{
for(int y=-4;y<=4;y++){
for(int x=-4;x<=4;x++)
printf("%5d",foo2(x,y));
printf("\n");
}
int x,y;
while(scanf("%d%d",&x,&y)==2){
printf("%d\n",foo(x,y));
}

return 0;
}