考察:思维
思路:
考虑四个端点的规律,而不是斜率相同的点的规律.除了第三象限其他端点的值与x、y都很好找.第三象限要进行x+1>=<y分类.代码写繁琐了,y总的思路将点分为在上、下、左、右更好.
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 using namespace std; 5 typedef long long LL; 6 int main() 7 { 8 int x,y; 9 scanf("%d%d",&x,&y); 10 if(x>=0&&y>=0) 11 { 12 int k = max(x,y); 13 LL t = (LL)(k+k)*(k+k); 14 k = x-y; 15 printf("%lld\n",t+k); 16 }else if(x>=0&&y<=0) 17 { 18 int k = max(x,abs(y)); 19 LL t = 2ll*k*(2*k+1); 20 k = abs(y)-x; 21 printf("%lld\n",t+k); 22 }else if(x<0&&y<0) 23 { 24 if(y-x==1) printf("%lld\n",(LL)(y+x)*(y+x)); 25 else if(y>x+1) 26 { 27 LL t= abs(x); 28 t = 2*t-1; 29 printf("%lld\n",t*t+y-x-1); 30 }else{ 31 LL t = abs(y); 32 t = 2*t+1; 33 printf("%lld\n",t*t+y-x-1); 34 } 35 }else if(x<=0&&y>=0) 36 { 37 int k = max(abs(x),y); 38 LL t = (LL)(2ll*k)*(2*k-1); 39 k = y-abs(x); 40 printf("%lld\n",t+k); 41 } 42 return 0; 43 }