fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int b[500][500];
  4. int tile = 1;
  5.  
  6. void TileBoard(int Start_x, int Start_y, int x, int y, int Size)
  7. {
  8. if(Size==1)
  9. return;
  10. int t = tile++;
  11. int s = Size/2;
  12.  
  13. if (x<Start_x+s && y<Start_y+s) ///top-left
  14. TileBoard(Start_x, Start_y, x, y, s);
  15. else
  16. {
  17. b[Start_x+s-1][Start_y+s-1] = t;
  18. TileBoard(Start_x, Start_y, Start_x+s-1, Start_y+s-1, s);
  19. }
  20.  
  21. if (x<Start_x+s && y>=Start_y+s) ///top-right
  22. TileBoard(Start_x, Start_y+s, x, y, s);
  23. else
  24. {
  25. b[Start_x+s-1][Start_y+s] = t;
  26. TileBoard(Start_x, Start_y+s, Start_x+s-1, Start_y+s, s);
  27. }
  28.  
  29. if (x>=Start_x+s && y<Start_y+s) ///bottom-left
  30. TileBoard(Start_x+s, Start_y, x, y, s);
  31. else
  32. {
  33. b[Start_x+s][Start_y+s-1] = t;
  34. TileBoard(Start_x+s, Start_y, Start_x+s, Start_y+s-1, s);
  35. }
  36.  
  37. if (x>=Start_x+s && y>=Start_y+s) ///bottom-right
  38. TileBoard(Start_x+s, Start_y+s, x, y, s);
  39. else
  40. {
  41. b[Start_x+s][Start_y+s] = t;
  42. TileBoard(Start_x+s, Start_y+s, Start_x+s, Start_y+s, s);
  43. }
  44. }
  45.  
  46. int main()
  47. {
  48. int n, x, y;
  49. cin>>n>>x>>y;
  50. TileBoard(1, 1, x, y, n); ///Let,Start point is (1,1)
  51. b[x][y] = -1; ///Let,defect point is -1
  52. for(int i = 1; i <= n; i++)
  53. {
  54. for(int j = 1; j <= n; j++)
  55. {
  56. cout<<setw(3)<<b[i][j]<<" ";
  57. }
  58. cout<<endl;
  59. }
  60. return 0;
  61. }
  62.  
Success #stdin #stdout 0s 16216KB
stdin
4 3 2
stdout
  2   2   3   3 
  2   1   1   3 
  4  -1   1   5 
  4   4   5   5