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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 #include #include #include #include using namespace std; const int N = 1 << 13; char tab[N + 7][N + 7]; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, -1, 0, 1}; int dx2[4] = {-1, 1, 1, -1}; int dy2[4] = {-1, -1, 1, 1}; int rot[4] = {0, 0, 3, 1}; void rysuj(int n, int x, int y, int obr) { if(n == 1) { tab[y + dy[(0 + obr) % 4]][x + dx[(0 + obr) % 4]] = (0 + obr) % 2; tab[y + dy[(1 + obr) % 4]][x + dx[(1 + obr) % 4]] = (1 + obr) % 2; tab[y + dy[(2 + obr) % 4]][x + dx[(2 + obr) % 4]] = (2 + obr) % 2; return; } int r = (1 << (n - 1)); tab[y + dy[(1 + obr) % 4]][x + dx[(1 + obr) % 4]] = (1 + obr) % 2; tab[y + (2 * r - 1) * dy[(0 + obr) % 4]][x + (2 * r - 1) * dx[(0 + obr) % 4]] = (0 + obr) % 2; tab[y + (2 * r - 1) * dy[(2 + obr) % 4]][x + (2 * r - 1) * dx[(2 + obr) % 4]] = (2 + obr) % 2; for(int i = 0; i < 4; ++i) { rysuj(n - 1, x + r * dx2[(i + obr) % 4], y + r * dy2[(i + obr) % 4], obr + rot[i]); } } int main() { ios_base::sync_with_stdio(0); int n, z; cin >> n >> z; if(n > 12) return 0; int R = 1 << (n + 1); for(int i = 0; i <= R; ++i) for(int j = 0; j <= R; ++j) tab[i][j] = 2; rysuj(n, R / 2, R / 2, 0); /* for(int i = 0; i <= R; ++i) { for(int j = 0; j <= R; ++j) { if(tab[i][j] == 2) cout << ' '; else if(tab[i][j] == 0) cout << "|"; else cout << "-"; } cout << endl; }*/ for(int x = 1; x < R; ++x) { tab[0][x] = tab[R][x] = 1; } for(int y = 1; y < R; ++y) { tab[y][0] = tab[y][R] = 0; } int x = 1; int y = R; int vx = 1; int vy = -1; int tt = 0; while(z--) { int t; cin >> t; while(tt < t) { x += vx; y += vy; if(tab[y][x] == 0) vx *= -1; else if(tab[y][x] == 1) vy *= -1; tt++; } cout << x << ' ' << R - y << '\n'; } return 0; }