Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n;
- void move(int x, int y, int c, int b[]);
- void arrayCopy(int a[], int b[]);
- bool o;
- int main() {
- cin >> n;
- o = true;
- int b[n * n];
- for (int y = 0; y < n; y++)
- {
- for (int x = 0; x < n; x++)
- {
- b[y * n + x] = -1;
- }
- }
- for (int y = 0; y < n; y++)
- {
- for (int x = 0; x < n; x++)
- {
- move(x, y, 1, b);
- }
- }
- return 0;
- }
- void move(int x, int y, int c, int b[])
- {
- if (x >= 0 && y >= 0 && x < n && y < n && b[y * n + x] == -1 && o)
- {
- int a[n*n];
- arrayCopy(b, a);
- a[y * n + x] = c++;
- bool p = true;
- for (int y = 0; y < n; y++) {
- for (int x = 0; x < n; x++) {
- if (a[y * n + x] == -1)
- {
- p = false;
- }
- }
- }
- if (p)
- {
- o = false;
- for (int y = 0; y < n; y++) {
- for (int x = 0; x < n; x++) {
- cout << a[y * n + x] << "\t";
- }
- cout << endl;
- }
- cout << endl;
- cout << endl;
- } else
- {
- move(x + 1, y + 2, c, a);
- move(x - 1, y + 2, c, a);
- move(x + 1, y - 2, c, a);
- move(x - 1, y - 2, c, a);
- move(x + 2, y + 1, c, a);
- move(x + 2, y - 1, c, a);
- move(x - 2, y + 1, c, a);
- move(x - 2, y - 1, c, a);
- }
- }
- }
- void arrayCopy(int a[], int b[])
- {
- for (int i = 0; i < n * n; i++)
- {
- b[i] = a[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement