1、螺旋矩阵求值(右上为1,往下走)
1 long long f(long long n,long long x,long long y){ 2 x = n - x + 1; 3 y = n - y + 1; 4 long long r = 0; 5 if(x <= y & x + y <= n+1) 6 { 7 r = x; 8 return 4*(r-1)*n - 4*(r-1)*(r-1) +1 + y-r; 9 } 10 if(x<=y & x+y >= n+1) 11 { 12 r = n- y + 1; 13 return 4*(r-1)*n - 4*(r-1)*(r-1) + 1 + n-2*r + 1 + x - r; 14 } 15 if(x>=y & x+y >= n+1) 16 { 17 r = n - x +1; 18 return 4*(r-1)*n - 4*(r-1)*(r-1) + 1 + 3*n-6*r + 3 - y + r; 19 } 20 if(x>=y & x+y <= n+1) 21 { 22 r = y; 23 return 4*(r-1)*n - 4*(r-1)*(r-1) + 1 + 4*n-8*r + 4 - x + r; 24 } 25 return 0; 26 }