#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; struct int2 { int2(int _x, int _y) { x = _x; y = _y; } bool isValid(int n) { return x >= 0 && y >= 0 && x < n && y < n; } bool operator ==(const int2& rhs) const { return x == rhs.x && y == rhs.y; } int x, y; }; static vector s_pos; bool hasBeen(int2 pos) { for(vector::const_iterator it = s_pos.begin(); it != s_pos.end(); ++it) { if(*it == pos) return true; } return false; } int move(int2 pos, int2 dir, int c, int n) { cout << pos.x << pos.y << " to " << dir.x << dir.y << " c: " << c << endl; pos.x += dir.x; pos.y += dir.y; if(hasBeen(pos)) return -1; s_pos.push_back(pos); ++c; if(pos == int2(n-1, n-1)) return c; else if(!pos.isValid(n)) return -1; vector moves; moves.push_back(move(pos, dir, c, n)); moves.push_back(move(pos, int2(-dir.x, dir.y), c, n)); moves.push_back(move(pos, int2(dir.x, -dir.y), c, n)); moves.push_back(move(pos, int2(-dir.x, -dir.y), c, n)); moves.push_back(move(pos, int2(dir.y, dir.x), c, n)); moves.push_back(move(pos, int2(-dir.y, dir.x), c, n)); moves.push_back(move(pos, int2(dir.y, -dir.x), c, n)); moves.push_back(move(pos, int2(-dir.y, -dir.x), c, n)); int minC = INT_MAX; for(vector::const_iterator it = moves.begin(); it != moves.end(); ++it) { if(*it > 0) minC = min(minC, *it); } return minC == INT_MAX ? -1 : minC; } int main(){ int n; cin >> n; //for(size_t i = 1; i < n; ++i) { s_pos.clear(); //for(size_t j = 1; j < n; ++j) { cout << move(int2(0,0), int2(1, 2), 0, n); } cout << endl; } return 0; }