#include #include #include #include #include using namespace std; class Punkt { public: int X, Y, W ; Punkt(int X = 0, int Y = 0, int W = 0) { this->X = X; this->Y = Y; this->W = W; } void drukuj() { cout << X << " " << Y << endl; } }; vector skoczek(Punkt p, int a, int b,int i,int N); class Tablica { public: int W, B; }; int main() { int N; cin >> N; for (int i = 1; i < N; i++) { for (int j = 1; j < N; j++) { Tablica **tab=new Tablica*[N]; for (int i = 0; i < N; i++)tab[i] = new Tablica[N]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { tab[i][j].W = 0; tab[i][j].B = 0; } } Punkt p(0, 0); vector Q; vector Q1; Q.push_back(p); while (Q.size()>0) { if (tab[Q[0].X][Q[0].Y].B == 1)Q.erase(Q.begin()); else { tab[Q[0].X][Q[0].Y].W = Q[0].W; tab[Q[0].X][Q[0].Y].B = 1; Q1 = skoczek(Q[0], i, j, Q[0].W,N); Q.reserve(Q.size() + Q1.size()); Q.insert(Q.end(), Q1.begin(), Q1.end()); Q.erase(Q.begin()); } } if (tab[N-1][N-1].W == 0)cout << -1 << " "; else cout << tab[N-1][N-1].W << " "; } cout << endl; } return 0; } vector skoczek(Punkt p, int a, int b, int i,int N) { vector Q; Punkt p1; p1.W = i + 1; p1.X = p.X + a; p1.Y = p.Y + b; if (p1.X>=0 && p1.X=0 && p1.Y=0 && p1.X=0 && p1.Y=0 && p1.X=0 && p1.Y= 0 && p1.X < N && p1.Y >= 0 && p1.Y < N)Q.push_back(p1); p1.X = p.X + b; p1.Y = p.Y + a; if (p1.X >= 0 && p1.X < N && p1.Y >= 0 && p1.Y < N)Q.push_back(p1); p1.X = p.X - b; p1.Y = p.Y + a; if (p1.X >= 0 && p1.X < N && p1.Y >= 0 && p1.Y < N)Q.push_back(p1); p1.X = p.X + b; p1.Y = p.Y - a; if (p1.X >= 0 && p1.X < N && p1.Y >= 0 && p1.Y < N)Q.push_back(p1); p1.X = p.X - b; p1.Y = p.Y - a; if (p1.X >= 0 && p1.X < N && p1.Y >= 0 && p1.Y < N)Q.push_back(p1); } return Q; }