Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n;
  6. void move(int x, int y, int c, int b[]);
  7. void arrayCopy(int a[], int b[]);
  8. bool o;
  9.  
  10. int main() {
  11. cin >> n;
  12. o = true;
  13. int b[n * n];
  14. for (int y = 0; y < n; y++)
  15. {
  16. for (int x = 0; x < n; x++)
  17. {
  18. b[y * n + x] = -1;
  19. }
  20. }
  21. for (int y = 0; y < n; y++)
  22. {
  23. for (int x = 0; x < n; x++)
  24. {
  25. move(x, y, 1, b);
  26. }
  27. }
  28. return 0;
  29. }
  30.  
  31. void move(int x, int y, int c, int b[])
  32. {
  33. if (x >= 0 && y >= 0 && x < n && y < n && b[y * n + x] == -1 && o)
  34. {
  35. int a[n*n];
  36. arrayCopy(b, a);
  37. a[y * n + x] = c++;
  38.  
  39. bool p = true;
  40. for (int y = 0; y < n; y++) {
  41. for (int x = 0; x < n; x++) {
  42. if (a[y * n + x] == -1)
  43. {
  44. p = false;
  45. }
  46. }
  47. }
  48. if (p)
  49. {
  50. o = false;
  51. for (int y = 0; y < n; y++) {
  52. for (int x = 0; x < n; x++) {
  53. cout << a[y * n + x] << "\t";
  54. }
  55. cout << endl;
  56. }
  57. cout << endl;
  58. cout << endl;
  59. } else
  60. {
  61.  
  62. move(x + 1, y + 2, c, a);
  63. move(x - 1, y + 2, c, a);
  64.  
  65. move(x + 1, y - 2, c, a);
  66. move(x - 1, y - 2, c, a);
  67.  
  68. move(x + 2, y + 1, c, a);
  69. move(x + 2, y - 1, c, a);
  70.  
  71. move(x - 2, y + 1, c, a);
  72. move(x - 2, y - 1, c, a);
  73. }
  74. }
  75. }
  76.  
  77. void arrayCopy(int a[], int b[])
  78. {
  79. for (int i = 0; i < n * n; i++)
  80. {
  81. b[i] = a[i];
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement