1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| #include <bits/stdc++.h> using namespace std;
const int MXN = 1 << 11; const int DIRs = 4; const int Xs[] = {1, 0, -1, 0}; const int Ys[] = {0, 1, 0, -1}; int N, cnt; bool mat[MXN][MXN]; inline int mv(int i, int p, int s) { int x(i + p * (1 << s)); if (x < 0) x += (1 << N); if (x >= (1 << N)) x -= (1 << N); return x; } void solve(int x, int y, int s) { if (s == N) return; for (int i(0); i != (1 << (N - s)); ++i) for (int j(0); j != (1 << (N - s)); ++j) if (!((i + j) & 1)) { for (int d(0); d != DIRs; ++d) mat[mv(x, i, s)][mv(y, j, s)] ^= mat[mv(x, i + Xs[d], s)][mv(y, j + Ys[d], s)]; } solve(x, y, s + 1); solve(x + (1 << s), y + (1 << s), s + 1); for (int i(0); i != (1 << (N - s)); ++i) for (int j(0); j != (1 << (N - s)); ++j) if ((i + j) & 1) { for (int d(0); d != DIRs; ++d) mat[mv(x, i, s)][mv(y, j, s)] ^= mat[mv(x, i + Xs[d], s)][mv(y, j + Ys[d], s)]; } } int main() { cin >> N; for (int i(0), x(0); i != (1 << N); ++i) for (int j(0); j != (1 << N); ++j) cin >> x, mat[i][j] = x; solve(0, 0, 0); for (int i(0); i != (1 << N); ++i) for (int j(0); j != (1 << N); ++j) cnt += mat[i][j]; cout << cnt << endl; for (int i(0); i != (1 << N); ++i) { for (int j(0); j != (1 << N); ++j) if (mat[i][j]) cout << i << ' ' << j << '\n'; cout << flush; } return 0; }
|