From dc1f0c4c0096013799416664894c5194dc7e1f52 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 28 Feb 2025 23:13:39 +0800 Subject: chore(store): move everything to store. --- store/works/solutions/leetcode/2.cpp | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 store/works/solutions/leetcode/2.cpp (limited to 'store/works/solutions/leetcode/2.cpp') diff --git a/store/works/solutions/leetcode/2.cpp b/store/works/solutions/leetcode/2.cpp new file mode 100644 index 0000000..4cf9c73 --- /dev/null +++ b/store/works/solutions/leetcode/2.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include + +using std::vector; + +struct P { + int x; + int y; +}; + +struct I { + int x; + int y; + int v; +}; + +P mm[]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; + +class Solution { +public: + vector> bicycleYard(vector &position, + vector> &terrain, + vector> &obstacle) { + std::vector>> visited( + terrain.size(), std::vector>(terrain.front().size())); + + std::queue q{{position[0], position[1], 1}}; + + bool f = false; + + while (true) { + if (f && q.size() == 1) { + break; + } + f = true; + + I b = q.back(); + q.pop_back(); + + if (b.v <= 0 || visited[b.x][b.y].count(b.v)) { + + } + + visited[b.x][b.y].insert(v); + + for (auto p : mm) { + int nx = x + p.x, ny = y + p.y; + if (nx >= 0 && nx < terrain.size() && ny >= 0 && + ny < terrain.front().size()) { + DFS(v + terrain[x][y] - terrain[nx][ny] - obstacle[nx][ny], nx, ny, + terrain, obstacle, visited); + } + } + } + + vector> result; + + for (int i = 0; i < terrain.size(); i++) { + for (int j = 0; j < obstacle.size(); j++) { + if ((i != position[0] || j != position[1]) && visited[i][j].count(1)) { + result.push_back({i, j}); + } + } + } + + return result; + } +}; \ No newline at end of file -- cgit v1.2.3