/* [NWERC'07] DORM by: Jan Kuipers */ using namespace std; #include #include #include vector m; void go (int Y, int X, int flip, int dep) { for (int x=0; x5 || Y>5)) go(3+X%3, Y, !flip, dep+1); if (dep==0) { m[flip? X-2 : Y-1][flip? Y-1 : X-2]='E'; if (m[0][0]=='B' && m[1][0]=='B' && m[0][1]=='B') m[0][0]='.'; if (m[1][0]=='B' && m[2][0]=='B' && m[0][1]=='B') m[1][0]='.'; if (m[0][1]=='B' && m[0][2]=='B' && m[1][0]=='B') m[0][1]='.'; } } int cnt () { int res=0; for (int y=0; y>runs; while (runs--) { int Y,X; cin>>Y>>X; m = vector(Y, string(X, '.')); if (X==1 && Y==1) { m[0][0]='E'; } else if (X==1) { m[0][0]='B'; m[Y-1][0]='B'; m[1][0]='E'; } else if (Y==1) { m[0][0]='B'; m[0][X-1]='B'; m[0][1]='E'; } else if ((X==2 && Y!=3) || X==3) { m[0][1]='E'; for (int y=0; y old=m; int cnt1 = cnt(); m = vector(Y, string(X, '.')); go(X,Y,1,0); int cnt2 = cnt(); if (cnt1>cnt2) m=old; } for (int y=0; y