From bf8edb724444d4ee7388a766b6b0e34a3153890d Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Wed, 11 Sep 2024 23:18:44 +0900 Subject: [PATCH 1/5] 65-9kyo-hwang --- ...\354\212\244 \352\262\214\354\236\204.cpp" | 33 +++++++++++++++++++ 9-kyo-hwang/README.md | 3 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Greedy/\353\224\224\355\216\234\354\212\244 \352\262\214\354\236\204.cpp" diff --git "a/9-kyo-hwang/Greedy/\353\224\224\355\216\234\354\212\244 \352\262\214\354\236\204.cpp" "b/9-kyo-hwang/Greedy/\353\224\224\355\216\234\354\212\244 \352\262\214\354\236\204.cpp" new file mode 100644 index 0000000..256384e --- /dev/null +++ "b/9-kyo-hwang/Greedy/\353\224\224\355\216\234\354\212\244 \352\262\214\354\236\204.cpp" @@ -0,0 +1,33 @@ +#include +#include +#include + +using namespace std; + +int solution(int N, int K, vector InEnemies) +{ + priority_queue NumofEnemiesBlocked; + int Round = 0; + + for(int Enemy : InEnemies) + { + N -= Enemy; + NumofEnemiesBlocked.emplace(Enemy); + + if(N < 0) + { + if(K == 0) + { + break; + } + + N += NumofEnemiesBlocked.top(); + NumofEnemiesBlocked.pop(); + K--; + } + + Round++; + } + + return Round; +} diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 546745d..90bde87 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -64,4 +64,5 @@ | 61차시 | 2024.8.08 | Implementation | [테이블 해시 함수](https://school.programmers.co.kr/learn/courses/30/lessons/147354) | [#214](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/214) | | 62차시 | 2024.8.12 | Graph Traversal | [무인도 여행](https://school.programmers.co.kr/learn/courses/30/lessons/154540) | [#217](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/217) | | 63차시 | 2024.9.3 | Binary Search | [구간 나누기2](https://www.acmicpc.net/problem/13397) | [#218](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/218) | -| 64차시 | 2024.9.8 | Binary Search | [징검다리](https://school.programmers.co.kr/learn/courses/30/lessons/43236) | [#221](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/221) | \ No newline at end of file +| 64차시 | 2024.9.8 | Binary Search | [징검다리](https://school.programmers.co.kr/learn/courses/30/lessons/43236) | [#221](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/221) | +| 65차시 | 2024.9.11 | Greedy | [디펜스 게임](https://school.programmers.co.kr/learn/courses/30/lessons/142085) | [#224](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/224) | From 086f215b97c2734f93a0db99847b4a1a119ef714 Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Sat, 14 Sep 2024 21:50:08 +0900 Subject: [PATCH 2/5] 66-9kyo-hwang --- 9-kyo-hwang/README.md | 1 + ...\354\235\270 \355\226\211\354\202\254.cpp" | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 "9-kyo-hwang/Sliding Window/\355\225\240\354\235\270 \355\226\211\354\202\254.cpp" diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 90bde87..4a316ba 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -66,3 +66,4 @@ | 63차시 | 2024.9.3 | Binary Search | [구간 나누기2](https://www.acmicpc.net/problem/13397) | [#218](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/218) | | 64차시 | 2024.9.8 | Binary Search | [징검다리](https://school.programmers.co.kr/learn/courses/30/lessons/43236) | [#221](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/221) | | 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) | \ No newline at end of file diff --git "a/9-kyo-hwang/Sliding Window/\355\225\240\354\235\270 \355\226\211\354\202\254.cpp" "b/9-kyo-hwang/Sliding Window/\355\225\240\354\235\270 \355\226\211\354\202\254.cpp" new file mode 100644 index 0000000..aa50591 --- /dev/null +++ "b/9-kyo-hwang/Sliding Window/\355\225\240\354\235\270 \355\226\211\354\202\254.cpp" @@ -0,0 +1,35 @@ +#include +#include +#include + +using namespace std; + +int solution(vector InWants, vector InNumbers, vector InDiscounts) +{ + unordered_map NumberbyWants; + for(int i = 0; i < 9; ++i) + { + NumberbyWants[InDiscounts[i]]++; + } + + int Answer = 0; + for(int i = 9; i < InDiscounts.size(); ++i) + { + NumberbyWants[InDiscounts[i]]++; + bool Flag = true; + + for(int j = 0; j < InWants.size(); ++j) + { + if(NumberbyWants[InWants[j]] != InNumbers[j]) + { + Flag = false; + break; + } + } + + Answer += Flag; + NumberbyWants[InDiscounts[i - 9]]--; + } + + return Answer; +} \ No newline at end of file From e172cbff33e493e18f68850942db3a06379c38ce Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Mon, 23 Sep 2024 00:25:14 +0900 Subject: [PATCH 3/5] 67-9kyo-hwang --- ... \354\261\204\354\232\260\352\270\260.cpp" | 125 ++++++++++++++++++ 9-kyo-hwang/README.md | 3 +- 2 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Graph Traversal/\355\215\274\354\246\220 \354\241\260\352\260\201 \354\261\204\354\232\260\352\270\260.cpp" diff --git "a/9-kyo-hwang/Graph Traversal/\355\215\274\354\246\220 \354\241\260\352\260\201 \354\261\204\354\232\260\352\270\260.cpp" "b/9-kyo-hwang/Graph Traversal/\355\215\274\354\246\220 \354\241\260\352\260\201 \354\261\204\354\232\260\352\270\260.cpp" new file mode 100644 index 0000000..d2a864a --- /dev/null +++ "b/9-kyo-hwang/Graph Traversal/\355\215\274\354\246\220 \354\241\260\352\260\201 \354\261\204\354\232\260\352\270\260.cpp" @@ -0,0 +1,125 @@ +#include +#include +#include +#include + +using namespace std; +using FPoint = pair; + +vector> GetBlocksFrom(vector>& Board, bool IsBoard = true) +{ + const vector Offset{{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; + auto OutOfBound = [&](int x, int y) + { + return x < 0 || x >= Board.size() || y < 0 || y >= Board.size(); + }; + + vector> Blocks; + + function DFS = [&](int x, int y) + { + Blocks.back().emplace_back(x, y); + Board[x][y] = (IsBoard ? 1 : 0); + + for(const auto& [dx, dy] : Offset) + { + int nx = x + dx, ny = y + dy; + if(!OutOfBound(nx, ny) && Board[nx][ny] == (IsBoard ? 0 : 1)) + { + DFS(nx, ny); + } + } + }; + + for(int i = 0; i < Board.size(); ++i) + { + for(int j = 0; j < Board.size(); ++j) + { + if(IsBoard && Board[i][j] == 0 + || !IsBoard && Board[i][j] == 1) + { + Blocks.push_back({}); + DFS(i, j); + } + } + } + + return Blocks; +} + +vector> GetGridFrom(const vector& Block) +{ + auto [MinX, MinY] = Block[0]; + auto [MaxX, MaxY] = Block[0]; + + for(const auto& [x, y] : Block) + { + if(x < MinX) MinX = x; + else if(x > MaxX) MaxX = x; + + if(y < MinY) MinY = y; + else if(y > MaxY) MaxY = y; + } + + vector> Grid(MaxX - MinX + 1, vector(MaxY - MinY + 1, 0)); + for(const auto& [x, y] : Block) + { + Grid[x - MinX][y - MinY] = 1; + } + + return Grid; +} + +int Rotate(vector>& Grid) +{ + vector> Rotated(Grid[0].size(), vector(Grid.size(), 0)); + int NumCell = 0; + + for(int i = 0; i < Grid.size(); ++i) + { + for(int j = 0; j < Grid[0].size(); ++j) + { + if(Grid[i][j] == 1) NumCell++; + Rotated[j][Grid.size() - 1 - i] = Grid[i][j]; + } + } + + Grid = Rotated; + return NumCell; +} + +int solution(vector> InGameBoard, vector> InTable) +{ + vector> BoardBlocks = GetBlocksFrom(InGameBoard, true); + vector> TableBlocks = GetBlocksFrom(InTable, false); + + set> UsedTableBlocks; + int Answer = 0; + + for(const vector& BoardBlock : BoardBlocks) + { + bool IsFilled = false; + vector> BoardBlockGrid = GetGridFrom(BoardBlock); + + for(const vector& TableBlock : TableBlocks) + { + if(IsFilled) break; + if(UsedTableBlocks.count(TableBlock)) continue; + + vector> TableBlockGrid = GetGridFrom(TableBlock); + for(int i = 0; i < 4; ++i) + { + int NumCell = Rotate(TableBlockGrid); + if(BoardBlockGrid == TableBlockGrid) + { + Answer += NumCell; + UsedTableBlocks.emplace(TableBlock); + IsFilled = true; + break; + } + } + } + } + + return Answer; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 4a316ba..fa7a2c5 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -66,4 +66,5 @@ | 63차시 | 2024.9.3 | Binary Search | [구간 나누기2](https://www.acmicpc.net/problem/13397) | [#218](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/218) | | 64차시 | 2024.9.8 | Binary Search | [징검다리](https://school.programmers.co.kr/learn/courses/30/lessons/43236) | [#221](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/221) | | 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) | \ No newline at end of file +| 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) | \ No newline at end of file From 7f2f382905011e92006ccca8d99b4a4fe07b5399 Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Tue, 1 Oct 2024 17:48:20 +0900 Subject: [PATCH 4/5] 68-9kyo-hwang --- ...4\353\223\234\352\262\214\354\236\204.cpp" | 77 +++++++++++++++++++ 9-kyo-hwang/README.md | 3 +- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Greedy/2024 KAKAO WINTER INTERNSHIP n + 1 \354\271\264\353\223\234\352\262\214\354\236\204.cpp" diff --git "a/9-kyo-hwang/Greedy/2024 KAKAO WINTER INTERNSHIP n + 1 \354\271\264\353\223\234\352\262\214\354\236\204.cpp" "b/9-kyo-hwang/Greedy/2024 KAKAO WINTER INTERNSHIP n + 1 \354\271\264\353\223\234\352\262\214\354\236\204.cpp" new file mode 100644 index 0000000..9ef1af4 --- /dev/null +++ "b/9-kyo-hwang/Greedy/2024 KAKAO WINTER INTERNSHIP n + 1 \354\271\264\353\223\234\352\262\214\354\236\204.cpp" @@ -0,0 +1,77 @@ +#include +#include +#include +#include + +using namespace std; + +struct Comparator +{ + bool operator()(const pair& Lhs, const pair& Rhs) const + { + const auto& [LhsCard, LhsCoin] = Lhs; + const auto& [RhsCard, RhsCoin] = Rhs; + + return LhsCoin == RhsCoin ? LhsCard < RhsCard : LhsCoin < RhsCoin; + } +}; + +int solution(int InCoin, vector InCards) +{ + const int N = (int)InCards.size(); + const int RequiredSum = N + 1; + reverse(InCards.begin(), InCards.end()); + + set, Comparator> Deck; + for(int i = 0; i < N / 3; ++i) + { + Deck.emplace(InCards.back(), 0); InCards.pop_back(); + } + + int Round; + for(Round = 1; !InCards.empty(); ++Round) + { + Deck.emplace(InCards.back(), 1); InCards.pop_back(); + Deck.emplace(InCards.back(), 1); InCards.pop_back(); + + bool FindCombination = false; + for(const auto& [Card, Coin] : Deck) + { + int TargetCard = RequiredSum - Card; + if(Card == TargetCard) + { + continue; + } + + int TargetCoin; + if(Deck.count({TargetCard, 0})) + { + TargetCoin = 0; + } + else if(Deck.count({TargetCard, 1})) + { + TargetCoin = 1; + } + else + { + continue; + } + + if(Coin + TargetCoin <= InCoin) + { + InCoin -= (Coin + TargetCoin); + Deck.erase({Card, Coin}); + Deck.erase({TargetCard, TargetCoin}); + FindCombination = true; + break; + } + } + + if(false == FindCombination) + { + break; + } + } + + return Round; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index fa7a2c5..d980cca 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -67,4 +67,5 @@ | 64차시 | 2024.9.8 | Binary Search | [징검다리](https://school.programmers.co.kr/learn/courses/30/lessons/43236) | [#221](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/221) | | 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) | \ No newline at end of file +| 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 From e3cb99478e126c6cdcf2144def6440637ea2c35a Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Tue, 8 Oct 2024 23:02:18 +0900 Subject: [PATCH 5/5] 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