File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+ using namespace std ;
3+ int a[1 << 7 ][1 << 7 ];
4+ int num;
5+ bool check (int n, int x, int y) {
6+ for (int i = x; i < x + n; i++) {
7+ for (int j = y; j < y + n; j++) {
8+ if (a[i][j])return false ;
9+ }
10+ }
11+ return true ;
12+ }
13+ void solve (int n, int x, int y) {
14+ num++;
15+ int n2 = n / 2 ;
16+ if (check (n2, x, y))a[x + n2 - 1 ][y + n2 - 1 ] = num;
17+ if (check (n2, x, y + n2))a[x + n2 - 1 ][y + n2] = num;
18+ if (check (n2, x + n2, y))a[x + n2][y + n2 - 1 ] = num;
19+ if (check (n2, x + n2, y + n2))a[x + n2][y + n2] = num;
20+ if (n == 2 )return ;
21+ solve (n2, x, y);
22+ solve (n2, x + n2, y);
23+ solve (n2, x, y + n2);
24+ solve (n2, x + n2, y + n2);
25+ }
26+ int main () {
27+ ios_base::sync_with_stdio (false ); cin.tie (NULL ); cout.tie (NULL );
28+ int n;
29+ cin >> n;
30+ n = (1 << n);
31+ int x, y;
32+ cin >> x >> y;
33+ a[n - y][x - 1 ] = -1 ;
34+ solve (n, 0 , 0 );
35+ for (int i = 0 ; i < n; i++) {
36+ for (int j = 0 ; j < n; j++) {
37+ cout << a[i][j] << ' ' ;
38+ }
39+ cout << ' \n ' ;
40+ }
41+
42+ }
You can’t perform that action at this time.
0 commit comments