#include #define ll long long using namespace std; ll a, b, c, d, e, f, n, BlockIdx, BlockRot, startm, endm; bool m [27][27]; int row[30]; int column[30]; vector>>> mx; bool running = true; int mvs = 0; vector> moves; vector> CheckAR = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; int Bidx(){ c = (c ^ a) + b; return c % 5; } int Brot(){ f = (f ^ d) + e; return f % 4; } void IM(){ for (ll i = 1; i <= n; i++){ for (ll j = 1; j <= n; j++){ cout << m[i][j] << ' '; } cout << '\n'; } cout << endl; } void Clear(){ // change later for (int i = 1; i <= n; i++){ row[i] = 0; column[i] = 0; } for (int i = 1; i <= n; i++){ for (int j = 1; j <= n; j++){ if (m[i][j]){ column[j]++; row[i]++; } } } for (int i = 1; i <= n; i++){ if (row[i] == n){ for (int j = 1; j <= n; j++){ m[i][j] = false; } } if (column[i] == n){ for (int j = 1; j <= n; j++){ m[j][i] = false; } } } } int AroundCells(int i, int j){ int sumcells = 0; for (pair xy : mx[BlockIdx][BlockRot]){ for (pair aroundc : CheckAR){ if (m[i + xy.first + aroundc.first][j + xy.second + aroundc.second]) sumcells++; } } return sumcells; } void PaintCells(int i, int j){ for (pair xy : mx[BlockIdx][BlockRot]){ m[i + xy.first][j + xy.second] = true; } } bool CanPlace(int i, int j){ for (pair xy : mx[BlockIdx][BlockRot]){ if (m[i + xy.first][j + xy.second]) return false; } return true; } void PlaceBlock(){ vector> movesp; vector aroundcnt; int bs = -1; for (int i = 1; i <= n; i++){ for (int j = 1; j <= n; j++){ if (CanPlace(i, j)){ int around = AroundCells(i, j); if (around > bs){ bs = around; movesp.clear(); movesp.push_back({i, j}); } else if (around == bs){ movesp.push_back({i, j}); } /*pair mv = {i, j}; movesp.push_back(mv); int around = AroundCells(i, j); aroundcnt.push_back(around);*/ } } } if (!movesp.empty()){ auto bM = movesp[rand() % movesp.size()]; moves.push_back(bM); /*auto maxi = max_element(aroundcnt.begin(), aroundcnt.end()); int idx = distance(aroundcnt.begin(), maxi); moves.push_back(move(movesp[idx])); int i1 = moves.back().first; int j1 = moves.back().second;*/ PaintCells(bM.first, bM.second); mvs++; } else running = false; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); freopen("block.in", "r", stdin); freopen("block.out", "w", stdout); cin >> n >> a >> b >> c >> d >> e >> f; vector>> block0 = { // bl0 tacno {{0, 0}, {-1, 0}, {0, -1}, {-1, -1}}, {{0, 0}, {0, 1}, {-1, 0}, {-1, 1}}, {{0, 0}, {1, 0}, {0, 1}, {1, 1}}, {{0, 0}, {0, -1}, {1, 0}, {1, -1}} }; vector>> block1 = { // bl1 tacno {{0, 0}, {-1, 0}, {0, -1}, {0, 0}}, {{0, 0}, {0, 1}, {-1, 0}, {0, 0}}, {{0, 0}, {1, 0}, {0, 1}, {0, 0}}, {{0, 0}, {0, -1}, {1, 0}, {0, 0}} }; vector>> block2 = { // bl2 tacno {{0, 0}, {-1, 0}, {0, -1}, {0, -2}}, {{0, 0}, {-1, 0}, {0, 1}, {-2,0}}, {{0, 0}, {1, 0}, {0, 1}, {0, 2}}, {{0, 0}, {0, -1}, {1, 0}, {2,0}} }; vector>> block3 = { // bl3 tacno {{0, 0}, {0, -1}, {0, -2}, {0, -3}}, {{0, 0}, {-1, 0}, {-2, 0}, {-3, 0}}, {{0, 0}, {0, 1}, {0, 2}, {0, 3}}, {{0, 0}, {1, 0}, {2, 0}, {3, 0}} }; vector>> block4 = { // bl4 tacno {{0, 0}, {-1, 0}, {-1, -1}, {-2, 0}}, {{0, 0}, {0, 1}, {0, 2}, {-1, 1}}, {{0, 0}, {1, 0}, {1, 1}, {2, 0}}, {{0, 0}, {0, -1}, {1, -1}, {0, -2}} }; mx.push_back(block0); mx.push_back(block1); mx.push_back(block2); mx.push_back(block3); mx.push_back(block4); memset(m,true,sizeof(m)); for (ll i = 1; i <= n; i++){ for (ll j = 1; j <= n; j++){ m[i][j] = false; } } while (running){ BlockIdx = Bidx(); BlockRot = Brot(); PlaceBlock(); Clear(); //cout << BlockIdx << ' ' << BlockRot << '\n'; //IM(); } cout << mvs << '\n'; for (pair out : moves){ cout << out.first << ' ' << out.second << '\n'; } return 0; }