#include #include #include using namespace std; #define INF 2000000000 char tab[40][40]; bool odw[40][40]; int odl[40][40][40][40]; int first[40][40][4]; char get() { char c; while((c=getchar())<=' '); return c; } int conv(int x, int y) { return x + 400*y; } bool go(int x ,int y, int H, int o,list & Q, int X, int Y) { if(x<0 || y<0 || x>=H || y>=H) return 0; if(odw[x][y]) return 0; if(tab[x][y]=='.') o++; if(o>=odl[x][y][X][Y]) return 0; odl[x][y][X][Y]=o; odw[x][y]=1; if(tab[x][y]=='.')Q.push_back(conv(x,y)); else Q.push_front(conv(x,y)); return 1; } int jeden() { int H; scanf("%d", &H); if(H==0) return 0; for(int i = 0; i<2*H-1; i++) for(int j = 0; j<2*H-1; j++) tab[i][j]='.'; for(int i = 0; i Q; Q.push_front(conv(X,Y)); for(int i = 0; i odl[X][Y][i][j]) first[X][Y][w] = odl[X][Y][i][j]; } } int mini = INF; for(int X = 0; X