#include #include #include #include #include #include #include #include #include #include #include #include #pragma comment(linker,"/STACK:102400000,102400000") using namespace std; char mp[55][55]; int n,m,sx,sy,tx,ty,dir[4][2]={1,0,-1,0,0,1,0,-1}; double dis[55][55]; struct thanks{ int x,y,k; double v; }now,temp; queue q; bool ok(thanks pt){ if(pt.x>=1 && pt.x<=n && pt.y>=1 && pt.y<=m && mp[pt.x][pt.y]!='#' && pt.k>0) return 1; else return 0; } void bfs(){ while(!q.empty()){ now=q.front(); q.pop(); for(int i=0;i<4;i++){ temp.x=now.x+dir[i][0]; temp.y=now.y+dir[i][1]; temp.k=now.k-1; if(ok(temp)){ temp.v=now.v+1.0*abs(mp[now.x][now.y]-mp[temp.x][temp.y])/now.k; if(dis[temp.x][temp.y]==-1 || temp.v0){ dis[sx][sy]=0; q.push(now); } bfs(); if(dis[tx][ty]==-1) printf("No Answer\n"); else printf("%.2lf\n",dis[tx][ty]); } //system("pause"); return 0; }