From e3cb99478e126c6cdcf2144def6440637ea2c35a Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Tue, 8 Oct 2024 23:02:18 +0900 Subject: [PATCH] 69-9kyo-hwang --- ...\353\212\224 \353\260\234\355\214\220.cpp" | 50 +++++++++++++++++++ 9-kyo-hwang/README.md | 3 +- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Graph Traversal/\354\202\254\353\235\274\354\247\200\353\212\224 \353\260\234\355\214\220.cpp" diff --git "a/9-kyo-hwang/Graph Traversal/\354\202\254\353\235\274\354\247\200\353\212\224 \353\260\234\355\214\220.cpp" "b/9-kyo-hwang/Graph Traversal/\354\202\254\353\235\274\354\247\200\353\212\224 \353\260\234\355\214\220.cpp" new file mode 100644 index 0000000..8fbc889 --- /dev/null +++ "b/9-kyo-hwang/Graph Traversal/\354\202\254\353\235\274\354\247\200\353\212\224 \353\260\234\355\214\220.cpp" @@ -0,0 +1,50 @@ +#include +#include +#include + +using namespace std; + +const vector> Offset{{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; + +vector> Board; + +bool OutOfBound(int r, int c) +{ + return r < 0 || r >= Board.size() || c < 0 || c >= Board[0].size(); +} + +int DFS(pair ALoc, pair BLoc) +{ + const auto& [r, c] = ALoc; + if(Board[r][c] == 0) + { + return 0; + } + + int Answer = 0; + Board[r][c] = 0; + + for(const auto& [dr, dc] : Offset) + { + int nr = r + dr, nc = c + dc; + if(OutOfBound(nr, nc) || Board[nr][nc] == 0) + { + continue; + } + + int RetVal = DFS(BLoc, {nr, nc}) + 1; + + if(Answer % 2 == 0 && RetVal % 2 == 1) Answer = RetVal; + else if(Answer % 2 == 0 && RetVal % 2 == 0) Answer = max(Answer, RetVal); + else if(Answer % 2 == 1 && RetVal % 2 == 1) Answer = min(Answer, RetVal); + } + + Board[r][c] = 1; + return Answer; +} + +int solution(vector> InBoard, vector InALoc, vector InBLoc) +{ + Board = InBoard; + return DFS({InALoc[0], InALoc[1]}, {InBLoc[0], InBLoc[1]}); +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index d980cca..244478c 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -68,4 +68,5 @@ | 65차시 | 2024.9.11 | Greedy | [디펜스 게임](https://school.programmers.co.kr/learn/courses/30/lessons/142085) | [#224](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/224) | | 66차시 | 2024.9.14 | Sliding Window | [할인 행사](https://school.programmers.co.kr/learn/courses/30/lessons/131127) | [#225](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/225) | | 67차시 | 2024.9.23 | Graph Traversal | [퍼즐 조각 채우기](https://school.programmers.co.kr/learn/courses/30/lessons/84021) | [#228](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/228) | -| 68차시 | 2024.10.1 | Greedy | [2024 KAKAO WINTER INTERNSHIP n + 1 카드 게임](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#230](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/230) | \ No newline at end of file +| 68차시 | 2024.10.1 | Greedy | [2024 KAKAO WINTER INTERNSHIP n + 1 카드 게임](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#230](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/230) | +| 69차시 | 2024.10.8 | Graph Traversal | [2022 KAKAO BLIND RECRUITMENT 사라지는 발판](https://school.programmers.co.kr/learn/courses/30/lessons/92345) | [#232](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/232) | \ No newline at end of file