fork download
  1. #include <iostream>
  2. #define MAX 17
  3.  
  4. using namespace std;
  5.  
  6. int K, x, y;
  7. int cnt = 0;
  8. int map[MAX][MAX] = {};
  9.  
  10. bool isNotHole(int x, int y, int len) {
  11. for (int i=x; i<x+len; i++) {
  12. for (int j=y; j<y+len; j++) {
  13. if(map[i][j]!=0) return false;
  14. }
  15. }
  16. return true;
  17. }
  18.  
  19. void search(int x, int y, int len) {
  20. cnt++;
  21. int halfLen = len/2;
  22.  
  23. if(isNotHole(x, y, halfLen)) map[x+halfLen-1][y+halfLen-1] = cnt;
  24. if(isNotHole(x, y+halfLen, halfLen)) map[x+halfLen-1][y+halfLen] = cnt;
  25. if(isNotHole(x+halfLen, y, halfLen)) map[x+halfLen][y+halfLen-1] = cnt;
  26. if(isNotHole(x+halfLen, y+halfLen, halfLen)) map[x+halfLen][y+halfLen] = cnt;
  27.  
  28. if(len == 2) return;
  29.  
  30. search(x, y, halfLen);
  31. search(x, y+halfLen, halfLen);
  32. search(x+halfLen, y, halfLen);
  33. search(x+halfLen, y+halfLen, halfLen);
  34.  
  35. }
  36.  
  37.  
  38. int main() {
  39. ios_base :: sync_with_stdio(false);
  40. cin.tie(NULL); cout.tie(NULL);
  41.  
  42. cin >> K >> x >> y;
  43. map[x-1][y-1] = -1;
  44.  
  45. search(0, 0, (1<<K));
  46.  
  47. for(int i=(1<<K)-1; i>=0; i--) {
  48. for(int j=0; j<(1<<K); j++) {
  49. cout << map[i][j] << ' ';
  50. }
  51. cout << '\n';
  52. }
  53.  
  54. return 0;
  55. }
Success #stdin #stdout 0.01s 5432KB
stdin
2
1 4
stdout
4 4 5 5 
4 1 1 5 
2 1 3 3 
2 2 3 -1