Advertisement
JosepRivaille

P70690: Tresors en un mapa (1)

Apr 21st, 2016
1,372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6. typedef vector<char> Node;
  7. typedef vector<Node> Graph;
  8.  
  9. void dfs_rec(const Graph &G, int x, int y, Graph &visited, bool &found)
  10. {
  11.   if (visited[x][y] == 'F' && !found) {
  12.     visited[x][y] = 'T';
  13.     if (G[x][y] == 't') found = true;
  14.     else if (G[x][y] != 'X') {
  15.       if (y != G[0].size() - 1) dfs_rec(G, x, y+1, visited, found); //Right
  16.       if (x != G.size() - 1) dfs_rec(G, x+1, y, visited, found); //Below
  17.       if (y != 0) dfs_rec(G, x , y-1, visited, found); //Left
  18.       if (x != 0) dfs_rec(G, x-1, y, visited, found); //Above
  19.     }
  20.   }
  21. }
  22.  
  23.  
  24. int main()
  25. {
  26.   int n, m;
  27.   cin >> n >> m;
  28.   int total_size = n*m;
  29.   Graph G(n, Node(m))   ;
  30.   for (int i = 0; i < n; ++i)
  31.     for (int j = 0; j < m; ++j)
  32.       cin >> G[i][j];
  33.   int x, y;
  34.   cin >> x >> y;
  35.   Graph visited(n, Node(m, 'F'));
  36.   bool found = false;
  37.   dfs_rec(G, x-1, y-1, visited, found);
  38.   if (found) cout << "yes" << endl;
  39.   else cout << "no" << endl;
  40. }
  41.  
  42. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement