Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.07 KB | None | 0 0
  1. typedef std::pair<int, int> location;
  2.  
  3. int Labyrinth(std::set<std::pair<location, location> > labyrinth, int size)
  4. {
  5.     std::list<location>::const_iterator it;
  6.     std::vector< std::vector<int> > map;
  7.     map.resize(size, std::vector<int>(size, 0));
  8.     std::queue<location> q;
  9.     location current = std::make_pair(0, 0);
  10.     map[0][0] = 1;
  11.     q.push(location(0, 0));
  12.     while (!q.empty()) {
  13.         location v = q.front();
  14.         q.pop();
  15.         location adjacent0 = location(v.first + 1, v.second);
  16.         location adjacent1 = location(v.first, v.second + 1);
  17.         location adjacent2 = location(v.first - 1, v.second);
  18.         location adjacent3 = location(v.first, v.second - 1);
  19.         std::pair<location, location> walls = std::pair<location, location>(v, adjacent0);
  20.         std::pair<location, location> walls1 = std::pair<location, location>(adjacent0, v);
  21.         const bool is_in = labyrinth.find(walls) == labyrinth.end();
  22.         const bool is_in1 = labyrinth.find(walls1) == labyrinth.end();
  23.         std::pair<location, location> walls2 = std::pair<location, location>(v, adjacent1);
  24.         std::pair<location, location> walls3 = std::pair<location, location>(adjacent1, v);
  25.         const bool is_in2 = labyrinth.find(walls2) == labyrinth.end();
  26.         const bool is_in3 = labyrinth.find(walls3) == labyrinth.end();
  27.         std::pair<location, location> walls4 = std::pair<location, location>(v, adjacent2);
  28.         std::pair<location, location> walls5 = std::pair<location, location>(adjacent2, v);
  29.         const bool is_in4 = labyrinth.find(walls4) == labyrinth.end();
  30.         const bool is_in5 = labyrinth.find(walls5) == labyrinth.end();
  31.         std::pair<location, location> walls6 = std::pair<location, location>(v, adjacent3);
  32.         std::pair<location, location> walls7 = std::pair<location, location>(adjacent3, v);
  33.         const bool is_in6 = labyrinth.find(walls6) == labyrinth.end();
  34.         const bool is_in7 = labyrinth.find(walls7) == labyrinth.end();
  35.             if (adjacent0.first >= 0 && adjacent0.second >= 0
  36.                 && adjacent0.first <= size -1 && adjacent0.second <= size - 1
  37.                 && map[adjacent0.first][adjacent0.second] == 0
  38.                 && is_in && is_in1) {
  39.                 q.push(adjacent0);
  40.                 map[adjacent0.first][adjacent0.second] = map[v.first][v.second] + 1;
  41.             }
  42.             if (adjacent1.first >= 0 && adjacent1.second >= 0
  43.                 && adjacent1.first <= size - 1 && adjacent1.second <= size - 1
  44.                 && map[adjacent1.first][adjacent1.second] == 0
  45.                 && is_in2 && is_in3) {
  46.                 q.push(adjacent1);
  47.                 map[adjacent1.first][adjacent1.second] = map[v.first][v.second] + 1;
  48.             }
  49.             if (adjacent2.first >= 0 && adjacent2.second >= 0
  50.                 && adjacent2.first <= size - 1 && adjacent2.second <= size - 1
  51.                 && map[adjacent2.first][adjacent2.second] == 0
  52.                 && is_in4 && is_in5) {
  53.                 q.push(adjacent2);
  54.                 map[adjacent2.first][adjacent2.second] = map[v.first][v.second] + 1;
  55.             }
  56.             if (adjacent3.first >= 0 && adjacent3.second >= 0
  57.                 && adjacent3.first <= size - 1 && adjacent3.second <= size - 1
  58.                 && map[adjacent3.first][adjacent3.second] == 0
  59.                 && is_in6 && is_in7) {
  60.                 q.push(adjacent3);
  61.                 map[adjacent3.first][adjacent3.second] = map[v.first][v.second] + 1;
  62.             }
  63.     }
  64.     return map [size-1][size-1];
  65. }
  66. //////////////////////////////////////////////////////////////////
  67.  
  68. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement