#include #define COORD(x,y) ((x)*C + (y)) #define BC(x,y) ((x)*16 + (y)) #define XOREGY(A,B) (A) = (A) ? !(B) : (B) bool def_coeffs[256][256]; bool **coeffs = new bool*[256]; int C, R; int RC; bool variables[256]; bool rights[256]; bool solve() { /* for (int i = 0; i < RC; i++) { for (int j = 0; j < RC; j++) { printf("%d ", coeffs[i][j]); } printf("\n"); } printf(" *** \n");*/ int x,y,z; int xs; xs = 0; for (x=0; x= RC) { } else { if (y!=xs) { bool tmp2 = rights[xs]; rights[xs] = rights[y]; rights[y] = tmp2; /*bool* tmp1 = coeffs[x]; coeffs[x] = coeffs[y]; coeffs[y] = tmp1;*/ bool tmp1; for (int i = 0; i < 256; ++i) { tmp1 = coeffs[xs][i]; coeffs[xs][i] = coeffs[y][i]; coeffs[y][i] = tmp1; } } for (y=xs+1; y=0; --xs) { for (x=0; !coeffs[xs][x]; ++x); variables[x] = rights[xs]; for (z = x+1; z < RC; ++z) { bool tmp = coeffs[x][z] && variables[z]; XOREGY(variables[x], tmp); } } return true; } int main() { for (int i=0; i<256; ++i) coeffs[i]= new bool[256]; for (int i=0; i<256; ++i) for (int j=0; j<256; ++j) def_coeffs[i][j]=false; for (int x=0; x<16; ++x) for (int y=0; y<16; ++y) { int o = BC(x, y); def_coeffs[o][o] = true; if (x>0) { int a = BC(x-1, y); def_coeffs[o][a] = true; def_coeffs[a][o] = true; } if (y>0) { int a = BC(x, y-1); def_coeffs[o][a] = true; def_coeffs[a][o] = true; } } while (scanf("%d %d ", &R, &C) && R) { RC = R*C; for (int x1=0; x1> %d,%d - %d,%d = %d\n", x1, y1, x2, y2, coeffs[COORD(x1, y1)][COORD(x2, y2)]); } } char buf[70]; for (int x=0; x> %s", buf); for (int y=0; y> %d \n", variables[i]); s+=variables[i] ? 1 : 0; } printf("You have to tap %d tiles.\n", s); } else printf("Damaged billboard.\n"); } return 0; }