#include #include #include #include #include struct point { int x, y; }; struct block { point pts[4], min, max; }; block blocks[5][4] = { { { 0, 0, -1, 0, 0, -1, -1, -1 } }, { { 0, 0, -1, 0, 0, -1, 0, 0 } }, { { 0, 0, -1, 0, 0, -1, -2, 0 } }, { { 0, 0, -1, 0, -2, 0, -3, 0 } }, { { 0, 0, 0, -1, -1, -1, 0, -2 } }, }; void init_blocks() { for (int i = 0; i < 5; i++) { for (int j = 1; j < 4; j++) { blocks[i][j].min = blocks[i][j].max = {}; } for (int j = 0; j < 4; j++) { blocks[i][1].pts[j].x = -blocks[i][0].pts[j].y; blocks[i][1].pts[j].y = blocks[i][0].pts[j].x; blocks[i][2].pts[j].x = -blocks[i][0].pts[j].x; blocks[i][2].pts[j].y = -blocks[i][0].pts[j].y; blocks[i][3].pts[j].x = blocks[i][0].pts[j].y; blocks[i][3].pts[j].y = -blocks[i][0].pts[j].x; } for (int j = 0; j < 4; j++) { for (int k = 1; k < 4; k++) { if (blocks[i][j].min.x > blocks[i][j].pts[k].x) blocks[i][j].min.x = blocks[i][j].pts[k].x; if (blocks[i][j].min.y > blocks[i][j].pts[k].y) blocks[i][j].min.y = blocks[i][j].pts[k].y; if (blocks[i][j].max.x < blocks[i][j].pts[k].x) blocks[i][j].max.x = blocks[i][j].pts[k].x; if (blocks[i][j].max.y < blocks[i][j].pts[k].y) blocks[i][j].max.y = blocks[i][j].pts[k].y; } } } } struct rnd { int64_t x, y, z; void next() { z = (z ^ x) + y; } int type() { return z % 5; } int rot() { return z % 4; } }; int N; rnd abc, def; uint32_t table[32]; void dump_table(int iter) { std::cout << "Iter: " << iter << std::endl; for (int y = 0; y < N; y++) { uint32_t mask = 1; for (int x = 0; x < N; x++, mask <<= 1) { std::cout << (table[y] & mask ? '*' : '.'); } std::cout << std::endl; } } void clear_full() { uint32_t full = (1U << N) - 1; bool r[32], c[32]; uint32_t mask = 1; for (int y = 0; y < N; y++, mask <<= 1) { r[y] = table[y] == full; int cnt = 0; for (int x = 0; x < N; x++) { if (table[x] & mask) cnt++; } c[y] = cnt == N; } mask = 1; for (int y = 0; y < N; y++, mask <<= 1) { if (r[y]) table[y] = 0; if (c[y]) { for (int x = 0; x < N; x++) { table[x] &= ~mask; } } } } void find_points(std::vector& pos) { while (true) { abc.next(); def.next(); int t = abc.type(), r = def.rot(); block& blk = blocks[t][r]; bool not_placed = true; for (int x = -blk.min.x; not_placed && x < N - blk.max.x; x++) { for (int y = -blk.min.y; y < N - blk.max.y; y++) { bool empty = true; for (int p = 0; p < 4; p++) { uint32_t mask = 1 << (x + blk.pts[p].x); if (table[y + blk.pts[p].y] & mask) { empty = false; break; } } if (empty) { for (int p = 0; p < 4; p++) { uint32_t mask = 1 << (x + blk.pts[p].x); table[y + blk.pts[p].y] |= mask; } not_placed = false; pos.push_back({ x, y }); break; } } } //dump_table(pos.size()); clear_full(); //dump_table(pos.size()); if (not_placed) break; } } int main() { init_blocks(); // input std::ifstream fin("block.in"); fin >> N >> abc.x >> abc.y >> abc.z >> def.x >> def.y >> def.z; // init table memset(table, 0, sizeof(table)); // find points std::vector points; find_points(points); // output std::ofstream fout("block.out"); fout << points.size() << std::endl; for (auto pt : points) { fout << pt.y + 1 << " " << pt.x + 1 << std::endl; } }