Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef std::pair<int, int> location;
- int Labyrinth(std::set<std::pair<location, location> > labyrinth, int size)
- {
- std::list<location>::const_iterator it;
- std::vector< std::vector<int> > map;
- map.resize(size, std::vector<int>(size, 0));
- std::queue<location> q;
- location current = std::make_pair(0, 0);
- map[0][0] = 1;
- q.push(location(0, 0));
- while (!q.empty()) {
- location v = q.front();
- q.pop();
- location adjacent0 = location(v.first + 1, v.second);
- location adjacent1 = location(v.first, v.second + 1);
- location adjacent2 = location(v.first - 1, v.second);
- location adjacent3 = location(v.first, v.second - 1);
- std::pair<location, location> walls = std::pair<location, location>(v, adjacent0);
- std::pair<location, location> walls1 = std::pair<location, location>(adjacent0, v);
- const bool is_in = labyrinth.find(walls) == labyrinth.end();
- const bool is_in1 = labyrinth.find(walls1) == labyrinth.end();
- std::pair<location, location> walls2 = std::pair<location, location>(v, adjacent1);
- std::pair<location, location> walls3 = std::pair<location, location>(adjacent1, v);
- const bool is_in2 = labyrinth.find(walls2) == labyrinth.end();
- const bool is_in3 = labyrinth.find(walls3) == labyrinth.end();
- std::pair<location, location> walls4 = std::pair<location, location>(v, adjacent2);
- std::pair<location, location> walls5 = std::pair<location, location>(adjacent2, v);
- const bool is_in4 = labyrinth.find(walls4) == labyrinth.end();
- const bool is_in5 = labyrinth.find(walls5) == labyrinth.end();
- std::pair<location, location> walls6 = std::pair<location, location>(v, adjacent3);
- std::pair<location, location> walls7 = std::pair<location, location>(adjacent3, v);
- const bool is_in6 = labyrinth.find(walls6) == labyrinth.end();
- const bool is_in7 = labyrinth.find(walls7) == labyrinth.end();
- if (adjacent0.first >= 0 && adjacent0.second >= 0
- && adjacent0.first <= size -1 && adjacent0.second <= size - 1
- && map[adjacent0.first][adjacent0.second] == 0
- && is_in && is_in1) {
- q.push(adjacent0);
- map[adjacent0.first][adjacent0.second] = map[v.first][v.second] + 1;
- }
- if (adjacent1.first >= 0 && adjacent1.second >= 0
- && adjacent1.first <= size - 1 && adjacent1.second <= size - 1
- && map[adjacent1.first][adjacent1.second] == 0
- && is_in2 && is_in3) {
- q.push(adjacent1);
- map[adjacent1.first][adjacent1.second] = map[v.first][v.second] + 1;
- }
- if (adjacent2.first >= 0 && adjacent2.second >= 0
- && adjacent2.first <= size - 1 && adjacent2.second <= size - 1
- && map[adjacent2.first][adjacent2.second] == 0
- && is_in4 && is_in5) {
- q.push(adjacent2);
- map[adjacent2.first][adjacent2.second] = map[v.first][v.second] + 1;
- }
- if (adjacent3.first >= 0 && adjacent3.second >= 0
- && adjacent3.first <= size - 1 && adjacent3.second <= size - 1
- && map[adjacent3.first][adjacent3.second] == 0
- && is_in6 && is_in7) {
- q.push(adjacent3);
- map[adjacent3.first][adjacent3.second] = map[v.first][v.second] + 1;
- }
- }
- return map [size-1][size-1];
- }
- //////////////////////////////////////////////////////////////////
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement