#include<cstdio> usingnamespace std; constint dpos[] = {-4, -1, 1, 4}; int ans = 0, num = 0; int a[6][6], as = 0; int des[20];
voidinit() { char ch; int res = 0; for (int i = 1; i <= 4; i++) { for (int j = 1; j <= 4; j++) { scanf("%c", &ch); if (ch == '+') a[i][j] = 1, res++; else a[i][j] = 0; num = (num<<1)+a[i][j]; } scanf("\n"); } if (res == 0) ans = -1; }
intsearch(int now, int pos, int cnt) { int flag = 0; int nxt = now; int x = (pos-1)/4+1, y = (pos-1)%4+1; if (cnt == 0) { if (now == 0) return1; return0; } if (pos + cnt > 17 || pos > 16) return0; for (int i = 1; i < 4; i++) { if (x+i<=4) nxt ^= (1<<(16-((x+i-1)*4+y))); if (x-i>=1) nxt ^= (1<<(16-((x-i-1)*4+y))); if (y+i<=4) nxt ^= (1<<(16-((x-1)*4+y+i))); if (y-i>=1) nxt ^= (1<<(16-((x-1)*4+y-i))); } nxt ^= (1<<(16-pos)); flag = search(nxt, pos+1, cnt-1); if (flag == 1) { des[++as] = pos; return1; } flag = search(now, pos+1, cnt); return flag; }
voidwork() { int cnt; if (ans == -1) return (void) printf("0\n"); ans = 0; for (cnt = 1; cnt <= 16; cnt++) { ans = search(num, 1, cnt); if (ans != 0) break; } if (ans == 0) printf("Impossible\n"); elseprintf("%d\n", cnt); for (int i = as; i >= 1; i--) { int x = (des[i]-1)/4+1, y = (des[i]-1)%4+1; printf("%d %d\n", x, y); } }