Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- int a[10][20]={},hx[5]={0,1,-1,0,0},hy[5]={0,0,0,-1,1},source[10000],direction[10000],x0,y0,cay[10000],kq[100],cau[10000];
- int deny(int x, int y)
- {
- if (x>8 || x<1 || y>11 || y<1) return 0;
- if (x==1 && y>1 && y<11) return 0;
- if (y==6 && x<6) return 0;
- if ((x==3 || x==5) && (y==2 || y==4 || y==8 || y==10)) return 0;
- if (x==7 && (y!=3 && y!=9)) return 0;
- if (x==8 && (y<3 || y>9)) return 0;
- return 1;
- }
- int nut(int x, int y)
- {
- if ((x+y)%2==0) return 0;
- return 1;
- }
- void chep_cay(int k, int x, int y)
- {
- cay[2*k]=x; cay[2*k+1]=y;
- }
- void doc_cay(int k)
- {
- x0=cay[2*k]; y0=cay[2*k+1];
- }
- int check_direction(int k, int x, int y, int i)
- {
- for (k=source[k];k!=0;k=source[k])
- if (cay[2*k]==x && cay[2*k+1]==y && direction[k]==i) return 1;
- return 0;
- }
- int od(int k, int i)
- {
- if (k==1 && i==2) return 0;
- if (k==2 && i==1) return 0;
- if (k==3 && i==4) return 0;
- if (k==4 && i==3) return 0;
- return 1;
- }
- void inkq(int k)
- {
- int i,dem=1;
- for (i=0;k!=0;)
- {
- if (nut(cay[2*k],cay[2*k+1])==1) kq[i++]=direction[k];
- k=source[k];
- }
- for (i--;i>=0 && printf("\n%d. ",dem++);i--)
- if (kq[i]==1) printf("Di len ");
- else if (kq[i]==2) printf("Di xuong ");
- else if (kq[i]==3) printf("Sang trai ");
- else if (kq[i]==4) printf("Sang phai ");
- printf("\n");
- }
- int c_cau(int k)
- {
- if (cau[k]!=0) return cau[k];
- return c_cau(source[k]);
- }
- void timduong()
- {
- int x=1,y=1,k,k0,i;
- k0=0; k=1; cau[0]=1;
- cay[0]=cay[1]=1;
- for (;k!=k0;k0++)
- {
- doc_cay(k0);
- for (i=1;i<=4;i++)
- {
- x=x0; y=y0;
- if (od(direction[k0],i)==1 && deny(x+hx[i],y+hy[i])==1 && c_cau(k0)!=a[x+hx[i]][y+hy[i]] && check_direction(k0,x,y,i)==0)
- {
- source[k]=k0; direction[k]=i;
- x+=hx[i]; y+=hy[i];
- chep_cay(k,x,y);
- if(a[x][y]==1 || a[x][y]==2) cau[k]=a[x][y];
- if (x==1 && y==11)
- {
- printf("Loi giai: ");
- inkq(k);
- return;
- }
- k++;
- }
- }
- }
- }
- int main()
- {
- a[1][1]=a[2][2]=a[5][1]=a[5][3]=a[4][4]=a[5][5]=a[8][6]=a[4][8]=a[6][8]=a[5][9]=a[2][10]=a[5][11]=a[1][11]=1;
- a[3][1]=a[4][2]=a[6][2]=a[3][3]=a[7][3]=a[6][4]=a[5][7]=a[7][9]=a[4][10]=a[3][11]=2;
- timduong();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment