#include <stdio.h>
#include <malloc.h>
#include <conio.h>
#define MAXSIZE 100
int ma[9][8];
int sign[9][8];
typedef struct number
{
int cx[MAXSIZE];
int cy[MAXSIZE];
int top;
}NUMBER;
NUMBER *Init_Number();
int Empty_Number(NUMBER *n);
int Push_Number(NUMBER *n,int x,int y);
int Pop_Number(NUMBER *n,int *x,int *y);
int Top_Number1(NUMBER *n);
int Top_Number2(NUMBER *n);
void Init_Ma();
int chance(NUMBER *n,int x,int y);
void print();
int main()
{
NUMBER *n;
int x,y;
n=Init_Number();
Init_Ma();
Push_Number(n,0,0);
while(1)
{
x=Top_Number1(n);
y=Top_Number2(n);
chance(n,x,y);
x=Top_Number1(n);
y=Top_Number2(n);
if(x==8&&y==7)
{
//printf("%d,%d",x,y);
break;
}
}
print();
return 0;
}
int chance(NUMBER *n,int x,int y)
{
//printf("%d,%d ",x,y);
if(sign[x][y+1]!=1&&sign[x][y+1]!=2&&ma[x][y+1]==0&&y+1<8)
{
Push_Number(n,x,y+1);return 1;
}
else if(sign[x+1][y]!=1&&sign[x+1][y]!=2&&ma[x+1][y]==0&&x+1<9)
{
Push_Number(n,x+1,y);return 1;
}
else if(sign[x][y-1]!=1&&sign[x][y-1]!=2&&ma[x][y-1]==0&&y-1>-1)
{
Push_Number(n,x,y-1);return 1;
}
else if(sign[x-1][y]!=1&&sign[x-1][y]!=2&&ma[x-1][y]==0&&x-1>-1)
{
Push_Number(n,x-1,y);return 1;
}
Pop_Number(n,&x,&y);
}
void print()
{
int i,j;
for(i=0;i<9;i++)
{
for(j=0;j<8;j++)
{
printf("%d",sign[i][j]);
}
printf("\n");
}
}
void Init_Ma()
{
int i,j;
for(i=0;i<9;i++)
{
for(j=0;j<8;j++)
{
ma[i][j]=0;
sign[i][j]=0;
}
}
ma[0][2]=1;ma[0][6]=1;ma[1][2]=1;ma[1][6]=1;
ma[2][4]=1;ma[2][5]=1;ma[2][7]=1;ma[3][1]=1;
ma[3][2]=1;ma[3][3]=1;ma[3][6]=1;ma[4][3]=1;
ma[5][1]=1;ma[5][5]=1;ma[5][7]=1;ma[6][1]=1;
ma[6][2]=1;ma[6][3]=1;ma[6][4]=1;ma[6][7]=1;
ma[7][0]=1;ma[7][1]=1;ma[7][5]=1;ma[7][7]=1;
ma[8][0]=1;ma[8][1]=1;
}
NUMBER *Init_Number()
{
NUMBER *n;
n=(NUMBER *)malloc(sizeof(NUMBER));
n->top=-1;
return n;
}
int Empty_Number(NUMBER *n)
{
if(n->top==-1) return 1;
else return 0;
}
int Push_Number(NUMBER *n,int x,int y)
{
if(n->top==MAXSIZE-1) return 0;
else
{
sign[x][y]=1;
n->top++;
n->cx[n->top]=x;
n->cy[n->top]=y;
return 1;
}
}
int Pop_Number(NUMBER *n,int *x,int *y)
{
if(Empty_Number(n)) return 0;
else
{
*x=n->cx[n->top];
*y=n->cy[n->top];
sign[*x][*y]=2;
n->top--;
return 1;
}
}
int Top_Number1(NUMBER *n)
{
if(Empty_Number(n)) return 0;
else{
return n->cx[n->top];
}
}
int Top_Number2(NUMBER *n)
{
if(Empty_Number(n)) return 0;
else{
return n->cy[n->top];
}
}
#include <malloc.h>
#include <conio.h>
#define MAXSIZE 100
int ma[9][8];
int sign[9][8];
typedef struct number
{
int cx[MAXSIZE];
int cy[MAXSIZE];
int top;
}NUMBER;
NUMBER *Init_Number();
int Empty_Number(NUMBER *n);
int Push_Number(NUMBER *n,int x,int y);
int Pop_Number(NUMBER *n,int *x,int *y);
int Top_Number1(NUMBER *n);
int Top_Number2(NUMBER *n);
void Init_Ma();
int chance(NUMBER *n,int x,int y);
void print();
int main()
{
NUMBER *n;
int x,y;
n=Init_Number();
Init_Ma();
Push_Number(n,0,0);
while(1)
{
x=Top_Number1(n);
y=Top_Number2(n);
chance(n,x,y);
x=Top_Number1(n);
y=Top_Number2(n);
if(x==8&&y==7)
{
//printf("%d,%d",x,y);
break;
}
}
print();
return 0;
}
int chance(NUMBER *n,int x,int y)
{
//printf("%d,%d ",x,y);
if(sign[x][y+1]!=1&&sign[x][y+1]!=2&&ma[x][y+1]==0&&y+1<8)
{
Push_Number(n,x,y+1);return 1;
}
else if(sign[x+1][y]!=1&&sign[x+1][y]!=2&&ma[x+1][y]==0&&x+1<9)
{
Push_Number(n,x+1,y);return 1;
}
else if(sign[x][y-1]!=1&&sign[x][y-1]!=2&&ma[x][y-1]==0&&y-1>-1)
{
Push_Number(n,x,y-1);return 1;
}
else if(sign[x-1][y]!=1&&sign[x-1][y]!=2&&ma[x-1][y]==0&&x-1>-1)
{
Push_Number(n,x-1,y);return 1;
}
Pop_Number(n,&x,&y);
}
void print()
{
int i,j;
for(i=0;i<9;i++)
{
for(j=0;j<8;j++)
{
printf("%d",sign[i][j]);
}
printf("\n");
}
}
void Init_Ma()
{
int i,j;
for(i=0;i<9;i++)
{
for(j=0;j<8;j++)
{
ma[i][j]=0;
sign[i][j]=0;
}
}
ma[0][2]=1;ma[0][6]=1;ma[1][2]=1;ma[1][6]=1;
ma[2][4]=1;ma[2][5]=1;ma[2][7]=1;ma[3][1]=1;
ma[3][2]=1;ma[3][3]=1;ma[3][6]=1;ma[4][3]=1;
ma[5][1]=1;ma[5][5]=1;ma[5][7]=1;ma[6][1]=1;
ma[6][2]=1;ma[6][3]=1;ma[6][4]=1;ma[6][7]=1;
ma[7][0]=1;ma[7][1]=1;ma[7][5]=1;ma[7][7]=1;
ma[8][0]=1;ma[8][1]=1;
}
NUMBER *Init_Number()
{
NUMBER *n;
n=(NUMBER *)malloc(sizeof(NUMBER));
n->top=-1;
return n;
}
int Empty_Number(NUMBER *n)
{
if(n->top==-1) return 1;
else return 0;
}
int Push_Number(NUMBER *n,int x,int y)
{
if(n->top==MAXSIZE-1) return 0;
else
{
sign[x][y]=1;
n->top++;
n->cx[n->top]=x;
n->cy[n->top]=y;
return 1;
}
}
int Pop_Number(NUMBER *n,int *x,int *y)
{
if(Empty_Number(n)) return 0;
else
{
*x=n->cx[n->top];
*y=n->cy[n->top];
sign[*x][*y]=2;
n->top--;
return 1;
}
}
int Top_Number1(NUMBER *n)
{
if(Empty_Number(n)) return 0;
else{
return n->cx[n->top];
}
}
int Top_Number2(NUMBER *n)
{
if(Empty_Number(n)) return 0;
else{
return n->cy[n->top];
}
}