#include #include #include #include #include #include #include int *arr; int mul1[4]={1,1,-1,-1}; int mul2[4]={1,-1,1,-1}; void KnightL(int i, int j, int n,int x1,int y1) { int x2,y2; int mul_i; int len = arr[x1*n+y1] + 1; for(mul_i=0;mul_i<4;mul_i++){ /* + + i j */ x2 = x1+mul1[mul_i]*i; y2 = y1+mul2[mul_i]*j; if(!(x2 < 0 || x2 >= n || y2 < 0 || y2 >= n)) { if(arr[x2*n+y2] == -1) { arr[x2*n+y2] = len; KnightL(i,j,n,x2,y2); } else if(arr[x2*n+y2] > len ) { arr[x2*n+y2] = len; KnightL(i,j,n,x2,y2); } } } if(i != j){ for(mul_i=0;mul_i<4;mul_i++){ /* + + i j */ x2 = x1+mul1[mul_i]*j; y2 = y1+mul2[mul_i]*i; if(!(x2 < 0 || x2 >= n || y2 < 0 || y2 >= n)) { if(arr[x2*n+y2] == -1) { arr[x2*n+y2] = len; KnightL(i,j,n,x2,y2); } else if(arr[x2*n+y2] > len ) { arr[x2*n+y2] = len; KnightL(i,j,n,x2,y2); } } } } } int main(){ int n,i,j,s,t; scanf("%d",&n); int *res = (int*) malloc(sizeof(int)*(n-1)*(n-1)); arr = (int*) malloc(sizeof(int)*n*n); // your code goes here for(i=1;i=i) printf("%d ",res[i*n+j]); else printf("%d ",res[j*n+i]); } printf("\n"); } return 0; }