1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| #include<bits/stdc++.h> using namespace std; int a,b,c,d,flag=0,Min; int Map[12][12]={0,1,0,0,0,1,1,1,0,1,0,1,0,0,0,1,0,0,0,0,1,0,0,1,0,1,0,1,0,1,1,1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,0}; int vis[20][20]; int dir[4][2]={0,1,0,-1,-1,0,1,0}; int stepA[100][2]; int stepB[100][2]; void dfs(int x,int y,int step){ if(step>Min){ return; } if(x==c&&y==d){ Min=step; return; } for(int i=0;i<4;i++){ int xx=x+dir[i][0]; int yy=y+dir[i][1]; if(xx<0||yy<0||xx>=12||yy>=12){ continue; } if(!vis[xx][yy]&&Map[xx][yy]==0){ vis[xx][yy]=1; dfs(xx,yy,step+1); vis[xx][yy]=0; } } return; } int main(){ scanf("%d %d %d %d",&a,&b,&c,&d); memset(vis,0,sizeof(vis)); vis[a][b]=1; Min=10000; dfs(a,b,0); if(Min==10000){ printf("10000\n"); } else{ printf("%d\n",Min); } return 0; }
|