#include #include #include #include #include #include #include using namespace std; bool mat[101][101][2][2][2][2]; char svet[101][101]; struct stav { int r,c,dist; bool kl[4]; }; stav mstav(int r,int c,int dist,bool a,bool b,bool cc,bool d) { stav tmp={r,c,dist,a,b,cc,d}; return tmp; } int dir[4][2]={-1,0, 1,0 ,0,1, 0,-1}; int main() { int r,c; int getnum[256]; getnum['b']=0; getnum['y']=1; getnum['r']=2; getnum['g']=3; while(cin>>r>>c,r+c) { getchar(); int sr,sc; for (int i=0;i fr; fr.push_back(mstav(sr,sc,0,0,0,0,0)); int result=-1; while(fr.size()>0) { stav top=*fr.begin(); fr.pop_front(); if (mat[top.r][top.c][top.kl[0]][top.kl[1]][top.kl[2]][top.kl[3]]==1) continue; mat[top.r][top.c][top.kl[0]][top.kl[1]][top.kl[2]][top.kl[3]]=1; if (top.r<0||top.r>=r||top.c<0||top.c>=c) continue; if (svet[top.r][top.c]=='#') continue; if (svet[top.r][top.c]=='X') { result=top.dist; break; } // cout<