Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <cmath>
- #include <math.h>
- #include <time.h>
- #include <cstdlib>
- #include <ctime>
- #include <string>
- #include <cstring>
- #include <string.h>
- using namespace std;
- const int N = 1005;
- bool was[N][N]; //
- int a[N][N], n;
- void build_board() {
- for (int i = 0; i <= n + 1; i++) {
- was[0][i] = true; // u
- was[i][n + 1] = true; // r
- was[i][0] = true; // l
- was[n + 1][i] = true; // d
- }
- }
- bool est_hod() {
- if (was[x + 1][y] == true && was[x - 1][y] == true && was[x][y + 1] == true && was[x][y - 1] == true)
- return false;
- return true;
- }
- int main() {
- cin >> n;
- build_board();
- x = y = 1; // NOW
- cnt = 0;
- while (est_hod()) {
- a[x][y] = ++cnt;
- was[x][y] = true;
- if (was[x][y + 1] == false)
- y++;
- else if (was[x + 1][y] == false)
- x++;
- else if (was[x][y - 1] == false)
- y--;
- else
- x--;
- }
- for (int i = 1; i <= n; i++) {
- for (int j = 1; j <= n; j++)
- cout << a[i][j] << " ";
- cout << endl;
- }
- }
Add Comment
Please, Sign In to add comment