#include <iostream> #include <stack> #include <vector> #include <string> #include <algorithm> #include <map> #include <set> #include <queue> using namespace std; bool endres = false; vector<pair<int,int>> res; vector<pair<int, int>> way = { {0,1},{1,0},{0,-1},{-1,0} }; void dfs(int maze[][6], int x, int y, int k) { if (x < 0 || y < 0 || x >= 5 || y >= 5 || maze[x][y] == 1) return; res[k] = pair<int, int>(x,y); if (x == 4 && y == 4) { for (int i = 0; i <= k; i++) printf("(%d, %d)\n", res[i].first, res[i].second); endres = true; return; } for (int i = 0; i < 4; i++) { if (endres) return; maze[x][y] = 1; dfs(maze, x + way[i].first, y + way[i].second, k + 1); maze[x][y] = 0; } } int main() { int maze[5+1][5+1]; for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) cin >> maze[i][j]; res.resize(5*5); dfs(maze,0,0,0); } /* F:\temp\22478366.11896\Main.cc:14: error: '>>' should be '> >' within a nested template argument list F:\temp\22478366.11896\Main.cc:15: error: '>>' should be '> >' within a nested template argument list F:\temp\22478366.11896\Main.cc:15: error: in C++98 'way' must be initialized by constructor, not by '{...}' F:\temp\22478366.11896\Main.cc:15: error: no matching function for call to 'std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > >::vector(<brace-enclosed initializer list>)' stl_vector.h:241: note: candidates are: std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::pair<int, int>, _Alloc = std::allocator<std::pair<int, int> >] stl_vector.h:207: note: std::vector<_Tp, _Alloc>::vector() [with _Tp = std::pair<int, int>, _Alloc = std::allocator<std::pair<int, int> >] F:\temp\22478366.11896\Main.cc: In function 'void dfs(int (*)[6], int, int, int)': F:\temp\22478366.11896\Main.cc:25: error: 'printf' was not declared in this scope */ |
Double click to view unformatted code.