#include<bits/stdc++.h> using namespace std; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; int m,n,sx,sy,ex,ey,yu=INT_MAX; char a[50][50]; bool v[50][50]; void bc(int x,int y,int t){ if(t>yu) return; if(x==ex&&y==ey){ yu=min(yu,t); } for(int i=0;i<=3;i++){ int tx=x+dx[i]; int ty=y+dy[i]; if(tx>=1&&tx<=m&&ty>=1&&ty<=n&&a[tx][ty]!='#'){ a[tx][ty]='#'; bc(tx,ty,t+1); a[tx][ty]='.'; } } } int main(){ cin>>m>>n; for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++){ cin>>a[i][j]; if(a[i][j]=='@'){ sx=i; sy=j; } if(a[i][j]=='*'){ ex=i; ey=j; } } } a[sx][sy]='#'; bc(sx,sy,0); if(yu==INT_MAX) cout<<-1; else cout<<yu; return 0; } /* 5 9 3 1 4 1 5 0 6 1 1 6 1 2 0 4 11 84 73264529 10 5 8 10 9 7 11 4 1 6 4 0 6 4 1 5 */ /************************************************************** Problem: 1900 User: huangsheng Language: C++ Result: Accepted Time:10 ms Memory:2076 kb ****************************************************************/