#include #include #include #include #include using namespace std; #define HMAX 20 #define WMAX 20 string map[HMAX]; int W,H; int dx[]={0,0,1,-1}; int dy[]={1,-1,0,0}; void fill_char(int x,int y,char c){ char b=map[y][x]; queue qy,qx; qx.push(x); qy.push(y); map[y][x]=c; while(!qx.empty()){ int nx=qx.front();qx.pop(); int ny=qy.front();qy.pop(); for(int i=0;i<4;i++){ int fy=ny+dy[i]; int fx=nx+dx[i]; if(fx>=0&&fx=0&&fy qy,qx,qc; qx.push(x); qy.push(y); qc.push(1); for(int i=0;i=0&&fx=0&&fycmap[ny][nx]+1){ qy.push(fy); qx.push(fx); qc.push(nc+1); cmap[fy][fx]=cmap[ny][nx]+1; } else if(map[fy][fx]!='#'&&cmap[fy][fx]>cmap[ny][nx]){ qy.push(fy); qx.push(fx); qc.push(nc); cmap[fy][fx]=cmap[ny][nx]; } } } } //for(int i=0;i>W>>H; for(int i=0;i>map[i]; } for(int i=0;i