#include #include #include #include #include #include #include int n; int **checked; typedef struct node{ int i; int j; int g; int h; struct node *next; }node_t; node_t *head = NULL; node_t *tail = NULL; void insert(int i, int j, int g, int h){ if(checked[i][j]==1) return; //printf("Insert: %d %d\n",i,j); checked[i][j] = 1; node_t *newnode = (node_t*)malloc(sizeof(node_t)); newnode->i = i; newnode->j = j; newnode->g = g; newnode->h = h; newnode->next = NULL; if(head==NULL){ head=newnode; } else{ tail->next=newnode; } tail=newnode; } int isEmpty(){ if(head==NULL){ return 1; } else return 0; } node_t *dequeue(){ node_t *ret; ret = head; head = head->next; return ret; } void testone(int i, int j,int g){ if(i<0) return; if(i>=n) return; if(j<0) return; if(j>=n) return; insert(i,j,g,0); } void initchecked(){ int i,j; for(i=0; ii, node->j); if(node==NULL){ printf("-1 "); return ; } else if(node->i==n-1 && node->j==n-1){ printf("%d ",node->g); return ; } testone(node->i - b, node->j + a, node->g+1); testone(node->i - a, node->j + b, node->g+1); testone(node->i + a, node->j + b, node->g+1); testone(node->i + b, node->j + a, node->g+1); testone(node->i - b, node->j - a, node->g+1); testone(node->i - a, node->j - b, node->g+1); testone(node->i + a, node->j - b, node->g+1); testone(node->i + b, node->j - a, node->g+1); } printf("-1 "); } int main(){ scanf("%d",&n); checked = (int **)malloc(n*sizeof(int *)); for(int i=0; i