Advertisement
Guest User

z

a guest
Jan 18th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int A[100][100];
  6. int x = 1;
  7.  
  8.  
  9.  
  10.  
  11. int Z(int i, int j, int ii, int jj)
  12. {
  13. if( i == ii || j == jj )
  14. {
  15. A[i][j] = x++;
  16. }
  17. else
  18. {
  19. Z( ii + (i-ii)/2 , jj + (j-jj)/2, ii, jj);
  20. Z( ii + (i-ii)/2 , j, ii, jj + (j-jj + 1)/2);
  21.  
  22. Z( i, jj + (j-jj)/2, ii + (i-ii + 1)/2 , jj);
  23. Z( i, j, ii + (i-ii + 1)/2, jj + (j-jj + 1)/2);
  24.  
  25. }
  26.  
  27. }
  28.  
  29.  
  30.  
  31. int main()
  32. {
  33. int N = 4;
  34. Z(1<<N ,1<<N ,1,1);
  35.  
  36. for(int i = 1; i <= 1<<N; i++ )
  37. {
  38. for(int j = 1; j <= 1<<N; j++)
  39. if(A[i][j]<10)
  40. cout<<" "<<A[i][j];
  41. else if(A[i][j]<100)
  42. cout<<" "<<A[i][j];
  43. else if(A[i][j]<1000)
  44. cout<<" "<<A[i][j];
  45.  
  46.  
  47. cout<<'\n'<<'\n';
  48.  
  49. }
  50.  
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement