请问wedding dress哪里买啊?# Fashion - 美丽时尚
a*e
1 楼
题目如下:
Given a 2D array of black and white entries representing a maze with
designated entrance and exit points, find a path from the entrance to the
exit, if one exists.
答案是
class Coordinate {
public:
int x, y;
const bool operator==(const Coordinate &that) const {
return (x == that.x && y == that.y);
}
};
bool is_feasible(const Coordinate &cur, const vector> &maze) {
return cur.x >= 0 && cur.x < maze.size() &&
cur.y >= 0 && cur.y < maze[cur.x].size() &&
maze[cur.x][cur.y] == 0;
}
bool search_maze_helper(vector> &maze, const Coordinate &cur,
const Coordinate &e, vector &path) {
if (cur == e) {
return true;
}
const array, 4> = {0, 1, 0, -1, 1, 0, -1, 0};
for (const array &s : shift) {
Coordinate next{cur.x + s[0], cur.y + s[1]};
if (is_feasible(next, maze)) {
maze[next.x][next.y] = 1;
path.emplace_back(next);
if (search_maze_helper(maze, next, e, path)) {
return true;
}
path.pop_back();
// maze[next.x][next.y] = 0; //这句在答案中没有,是不是答案错了?
}
}
return true;
}
vector search_maze(vector> maze, const Coordinate &s
, const Coordinate &e) {
vector path;
maze[s.x][s.y] = 1;
path.emplace_back(s);
if (search_maze_helper(maze, s, e, path)==false) {
path.pop_back();
}
return path;
}
其中有一个地方我觉得答案不正确并注释出来了,请问我想的对不对?多谢~
Given a 2D array of black and white entries representing a maze with
designated entrance and exit points, find a path from the entrance to the
exit, if one exists.
答案是
class Coordinate {
public:
int x, y;
const bool operator==(const Coordinate &that) const {
return (x == that.x && y == that.y);
}
};
bool is_feasible(const Coordinate &cur, const vector
return cur.x >= 0 && cur.x < maze.size() &&
cur.y >= 0 && cur.y < maze[cur.x].size() &&
maze[cur.x][cur.y] == 0;
}
bool search_maze_helper(vector
const Coordinate &e, vector
if (cur == e) {
return true;
}
const array
for (const array
Coordinate next{cur.x + s[0], cur.y + s[1]};
if (is_feasible(next, maze)) {
maze[next.x][next.y] = 1;
path.emplace_back(next);
if (search_maze_helper(maze, next, e, path)) {
return true;
}
path.pop_back();
// maze[next.x][next.y] = 0; //这句在答案中没有,是不是答案错了?
}
}
return true;
}
vector
, const Coordinate &e) {
vector
maze[s.x][s.y] = 1;
path.emplace_back(s);
if (search_maze_helper(maze, s, e, path)==false) {
path.pop_back();
}
return path;
}
其中有一个地方我觉得答案不正确并注释出来了,请问我想的对不对?多谢~