From 1f9f82f9e701bace1d1e6527b93d4618a93e9715 Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Mon, 29 Jul 2024 22:01:39 +0900 Subject: [PATCH 1/6] 58-9kyo-hwang --- 9-kyo-hwang/README.md | 3 +- ... \352\260\234\353\257\270\352\265\264.cpp" | 55 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Trie/14725 \352\260\234\353\257\270\352\265\264.cpp" diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 4ef3bc9..c576a7c 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -57,4 +57,5 @@ | 54차시 | 2024.7.04 | Data Structure | [16934 게임 닉네임](https://www.acmicpc.net/problem/16934) | [#197](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/197) | | 55차시 | 2024.7.09 | Simulation | [17144 미세먼지 안녕!](https://www.acmicpc.net/problem/16934) | [#202](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/202) | | 56차시 | 2024.7.12 | Tree | [15681 트리와 쿼리](https://www.acmicpc.net/problem/15681) | [#204](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/204) | -| 57차시 | 2024.7.15 | Dynamic Programming | [17070 파이프 옮기기 1](https://www.acmicpc.net/problem/17070) | [#206](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/206) | \ No newline at end of file +| 57차시 | 2024.7.15 | Dynamic Programming | [17070 파이프 옮기기 1](https://www.acmicpc.net/problem/17070) | [#206](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/206) | +| 58차시 | 2024.7.29 | Trie | [14725 개미굴](https://www.acmicpc.net/problem/14725) | [#207](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/207) | \ No newline at end of file diff --git "a/9-kyo-hwang/Trie/14725 \352\260\234\353\257\270\352\265\264.cpp" "b/9-kyo-hwang/Trie/14725 \352\260\234\353\257\270\352\265\264.cpp" new file mode 100644 index 0000000..9472230 --- /dev/null +++ "b/9-kyo-hwang/Trie/14725 \352\260\234\353\257\270\352\265\264.cpp" @@ -0,0 +1,55 @@ +#include +#include +#include + +using namespace std; + +struct FNode +{ + map Node; +}; + +FNode* Root; + +void Print(FNode* InNode = Root, const string& Prefix="") +{ + if(InNode == nullptr) + { + return; + } + + for(const auto& [Data, Next] : InNode->Node) + { + cout << Prefix << Data << "\n"; + Print(Next, Prefix + "--"); + } +} + +int main() +{ + cin.tie(nullptr)->sync_with_stdio(false); + + Root = new FNode(); + + int N; cin >> N; + for(int n = 0; n < N; ++n) + { + FNode* Ptr = Root; + + int K; cin >> K; + for(int k = 0; k < K; ++k) + { + string Info; cin >> Info; + if(Ptr->Node.count(Info) == 0) + { + Ptr->Node[Info] = new FNode(); + } + + Ptr = Ptr->Node[Info]; + } + } + + Print(); + + return 0; +} \ No newline at end of file From 91fa21c1a00b10aafac19d0a76efced24ee6d268 Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Thu, 1 Aug 2024 20:32:00 +0900 Subject: [PATCH 2/6] 59-9kyo-hwang --- ...4\353\262\240\354\235\264\355\204\260.cpp" | 38 +++++++++++++++++++ 9-kyo-hwang/README.md | 3 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Greedy/\353\247\210\353\262\225\354\235\230 \354\227\230\353\246\254\353\262\240\354\235\264\355\204\260.cpp" diff --git "a/9-kyo-hwang/Greedy/\353\247\210\353\262\225\354\235\230 \354\227\230\353\246\254\353\262\240\354\235\264\355\204\260.cpp" "b/9-kyo-hwang/Greedy/\353\247\210\353\262\225\354\235\230 \354\227\230\353\246\254\353\262\240\354\235\264\355\204\260.cpp" new file mode 100644 index 0000000..623518f --- /dev/null +++ "b/9-kyo-hwang/Greedy/\353\247\210\353\262\225\354\235\230 \354\227\230\353\246\254\353\262\240\354\235\264\355\204\260.cpp" @@ -0,0 +1,38 @@ +#include +#include + +using namespace std; + +int solution(int Storey) +{ + int Answer = 0; + + while(Storey) + { + int Remainder = Storey % 10; + int Quotient = Storey / 10; + + if(Remainder < 5) // 예: 54 + { + Answer += Remainder; // 54 -> 50 + } + else if(Remainder > 5) // 예: 16 + { + ++Quotient; + Answer += 10 - Remainder; // 16 -> 20 + } + else + { + if(Quotient % 10 >= 5) // 예: 55 -> 60 / 25 -> 20 + { + ++Quotient; + } + + Answer += Remainder; + } + + Storey = Quotient; + } + + return Answer; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index c576a7c..0e822d3 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -58,4 +58,5 @@ | 55차시 | 2024.7.09 | Simulation | [17144 미세먼지 안녕!](https://www.acmicpc.net/problem/16934) | [#202](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/202) | | 56차시 | 2024.7.12 | Tree | [15681 트리와 쿼리](https://www.acmicpc.net/problem/15681) | [#204](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/204) | | 57차시 | 2024.7.15 | Dynamic Programming | [17070 파이프 옮기기 1](https://www.acmicpc.net/problem/17070) | [#206](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/206) | -| 58차시 | 2024.7.29 | Trie | [14725 개미굴](https://www.acmicpc.net/problem/14725) | [#207](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/207) | \ No newline at end of file +| 58차시 | 2024.7.29 | Trie | [14725 개미굴](https://www.acmicpc.net/problem/14725) | [#207](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/207) | +| 59차시 | 2024.8.01 | Greedy | [마법의 엘리베이터](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | [#210](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/210) | \ No newline at end of file From 30b109d487154dfa61a4bd65180b96d20c28567c Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Mon, 5 Aug 2024 22:01:32 +0900 Subject: [PATCH 3/6] [60-9kyo-hwang] --- ...4\355\226\211\355\225\230\352\270\260.cpp" | 79 +++++++++++++++++++ 9-kyo-hwang/README.md | 3 +- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Implementation/\352\263\274\354\240\234 \354\247\204\355\226\211\355\225\230\352\270\260.cpp" diff --git "a/9-kyo-hwang/Implementation/\352\263\274\354\240\234 \354\247\204\355\226\211\355\225\230\352\270\260.cpp" "b/9-kyo-hwang/Implementation/\352\263\274\354\240\234 \354\247\204\355\226\211\355\225\230\352\270\260.cpp" new file mode 100644 index 0000000..78ca1d9 --- /dev/null +++ "b/9-kyo-hwang/Implementation/\352\263\274\354\240\234 \354\247\204\355\226\211\355\225\230\352\270\260.cpp" @@ -0,0 +1,79 @@ +#include +#include +#include + +using namespace std; + +struct FPlan +{ + string Name; + int Start; + int Playtime; + + FPlan() {} + FPlan(const string& InName, const string& InStart, const string& InPlaytime) + { + Name = InName; + Start = stoi(InStart.substr(0, 2)) * 60 + stoi(InStart.substr(3, 2)); + Playtime = stoi(InPlaytime); + } + + const bool operator<(const FPlan& Rhs) const + { + return Start < Rhs.Start; + } +}; + +vector solution(vector> InPlans) +{ + vector Plans; + for(const vector& Plan : InPlans) + { + Plans.push_back({Plan[0], Plan[1], Plan[2]}); + } + + sort(Plans.begin(), Plans.end()); + + vector Result; + vector Paused; + + for(int i = 0; i < Plans.size() - 1; ++i) + { + int TimeDifference = Plans[i + 1].Start - Plans[i].Start; + if(Plans[i].Playtime > TimeDifference) + { + Plans[i].Playtime -= TimeDifference; + Paused.emplace_back(i); + continue; + } + + TimeDifference -= Plans[i].Playtime; + Plans[i].Playtime = 0; + Result.emplace_back(Plans[i].Name); + + while(TimeDifference > 0 && !Paused.empty()) + { + int Index = Paused.back(); + if(Plans[Index].Playtime > TimeDifference) + { + Plans[Index].Playtime -= TimeDifference; + break; + } + + TimeDifference -= Plans[Index].Playtime; + Plans[Index].Playtime = 0; + Result.emplace_back(Plans[Index].Name); + Paused.pop_back(); + } + } + + Result.emplace_back(Plans.back().Name); + + while(!Paused.empty()) + { + Result.emplace_back(Plans[Paused.back()].Name); + Paused.pop_back(); + } + + return Result; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 0e822d3..2bb01f0 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -59,4 +59,5 @@ | 56차시 | 2024.7.12 | Tree | [15681 트리와 쿼리](https://www.acmicpc.net/problem/15681) | [#204](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/204) | | 57차시 | 2024.7.15 | Dynamic Programming | [17070 파이프 옮기기 1](https://www.acmicpc.net/problem/17070) | [#206](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/206) | | 58차시 | 2024.7.29 | Trie | [14725 개미굴](https://www.acmicpc.net/problem/14725) | [#207](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/207) | -| 59차시 | 2024.8.01 | Greedy | [마법의 엘리베이터](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | [#210](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/210) | \ No newline at end of file +| 59차시 | 2024.8.01 | Greedy | [마법의 엘리베이터](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | [#210](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/210) | +| 60차시 | 2024.8.05 | Implementation | [과제 진행하기](https://school.programmers.co.kr/learn/courses/30/lessons/176962) | [#213](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/213) | \ No newline at end of file From 92089962d6d2f40d4e40492b15517482217c1b14 Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Thu, 8 Aug 2024 10:43:10 +0900 Subject: [PATCH 4/6] 61-9kyo-hwang --- ...\354\213\234 \355\225\250\354\210\230.cpp" | 26 +++++++++++++++++++ 9-kyo-hwang/README.md | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Implementation/\355\205\214\354\235\264\353\270\224 \355\225\264\354\213\234 \355\225\250\354\210\230.cpp" diff --git "a/9-kyo-hwang/Implementation/\355\205\214\354\235\264\353\270\224 \355\225\264\354\213\234 \355\225\250\354\210\230.cpp" "b/9-kyo-hwang/Implementation/\355\205\214\354\235\264\353\270\224 \355\225\264\354\213\234 \355\225\250\354\210\230.cpp" new file mode 100644 index 0000000..f67c7ef --- /dev/null +++ "b/9-kyo-hwang/Implementation/\355\205\214\354\235\264\353\270\224 \355\225\264\354\213\234 \355\225\250\354\210\230.cpp" @@ -0,0 +1,26 @@ +#include +#include +#include + +using namespace std; + +int solution(vector> Data, int Col, int RowBegin, int RowEnd) +{ + sort(Data.begin(), Data.end(), [&](const auto& Lhs, const auto& Rhs) + { + return Lhs[Col - 1] == Rhs[Col - 1] ? Lhs[0] > Rhs[0] : Lhs[Col - 1] < Rhs[Col - 1]; + }); + + int HashVal = 0; + for(int i = RowBegin; i <= RowEnd; ++i) + { + int S_i = 0; + for(const int Val : Data[i - 1]) + { + S_i += Val % i; + } + HashVal ^= S_i; + } + + return HashVal; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 2bb01f0..f8ea7a9 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -60,4 +60,5 @@ | 57차시 | 2024.7.15 | Dynamic Programming | [17070 파이프 옮기기 1](https://www.acmicpc.net/problem/17070) | [#206](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/206) | | 58차시 | 2024.7.29 | Trie | [14725 개미굴](https://www.acmicpc.net/problem/14725) | [#207](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/207) | | 59차시 | 2024.8.01 | Greedy | [마법의 엘리베이터](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | [#210](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/210) | -| 60차시 | 2024.8.05 | Implementation | [과제 진행하기](https://school.programmers.co.kr/learn/courses/30/lessons/176962) | [#213](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/213) | \ No newline at end of file +| 60차시 | 2024.8.05 | Implementation | [과제 진행하기](https://school.programmers.co.kr/learn/courses/30/lessons/176962) | [#213](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/213) | +| 60차시 | 2024.8.08 | Implementation | [테이블 해시 함수](https://school.programmers.co.kr/learn/courses/30/lessons/147354) | [#214](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/214) | \ No newline at end of file From f754cc5586d4fd790bde7f8ad832a8d41917b793 Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Mon, 12 Aug 2024 22:50:01 +0900 Subject: [PATCH 5/6] 62-9kyo-hwang --- ...\353\217\204 \354\227\254\355\226\211.cpp" | 45 +++++++++++++++++++ 9-kyo-hwang/README.md | 3 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Graph Traversal/\353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.cpp" diff --git "a/9-kyo-hwang/Graph Traversal/\353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.cpp" "b/9-kyo-hwang/Graph Traversal/\353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.cpp" new file mode 100644 index 0000000..c03e4b5 --- /dev/null +++ "b/9-kyo-hwang/Graph Traversal/\353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.cpp" @@ -0,0 +1,45 @@ +#include +#include +#include + +using namespace std; + +int Merge(vector& Maps, int x, int y) +{ + if(x < 0 || x >= Maps.size() || y < 0 || y >= Maps[0].size() || Maps[x][y] == 'X') + { + return 0; + } + + int Day = Maps[x][y] - '0'; + Maps[x][y] = 'X'; + + return Day + + Merge(Maps, x - 1, y) + + Merge(Maps, x, y + 1) + + Merge(Maps, x + 1, y) + + Merge(Maps, x, y - 1); +} + +vector solution(vector Maps) +{ + vector DaysofStay; + for(int i = 0; i < Maps.size(); ++i) + { + for(int j = 0; j < Maps[0].size(); ++j) + { + if(Maps[i][j] != 'X') + { + DaysofStay.emplace_back(Merge(Maps, i, j)); + } + } + } + + if(DaysofStay.empty()) + { + return {-1}; + } + + sort(DaysofStay.begin(), DaysofStay.end()); + return DaysofStay; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index f8ea7a9..8ed2789 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -61,4 +61,5 @@ | 58차시 | 2024.7.29 | Trie | [14725 개미굴](https://www.acmicpc.net/problem/14725) | [#207](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/207) | | 59차시 | 2024.8.01 | Greedy | [마법의 엘리베이터](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | [#210](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/210) | | 60차시 | 2024.8.05 | Implementation | [과제 진행하기](https://school.programmers.co.kr/learn/courses/30/lessons/176962) | [#213](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/213) | -| 60차시 | 2024.8.08 | Implementation | [테이블 해시 함수](https://school.programmers.co.kr/learn/courses/30/lessons/147354) | [#214](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/214) | \ No newline at end of file +| 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) | \ No newline at end of file From abe77063d7679458832cea6fc934e99c12221e97 Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Tue, 3 Sep 2024 22:10:04 +0900 Subject: [PATCH 6/6] 63-9kyo-hwang --- ...353\202\230\353\210\204\352\270\260 2.cpp" | 59 +++++++++++++++++++ 9-kyo-hwang/README.md | 3 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Binary Search/13397 \352\265\254\352\260\204 \353\202\230\353\210\204\352\270\260 2.cpp" diff --git "a/9-kyo-hwang/Binary Search/13397 \352\265\254\352\260\204 \353\202\230\353\210\204\352\270\260 2.cpp" "b/9-kyo-hwang/Binary Search/13397 \352\265\254\352\260\204 \353\202\230\353\210\204\352\270\260 2.cpp" new file mode 100644 index 0000000..8362fee --- /dev/null +++ "b/9-kyo-hwang/Binary Search/13397 \352\265\254\352\260\204 \353\202\230\353\210\204\352\270\260 2.cpp" @@ -0,0 +1,59 @@ +#include +#include +#include + +using namespace std; + +int main() +{ + cin.tie(nullptr)->sync_with_stdio(false); + + int N, M; cin >> N >> M; + + vector Nums(N); + for(int& Num : Nums) + { + cin >> Num; + } + + auto IsValid = [&](int EstimateScore) + { + int Count = 1; + int Min = Nums[0], Max = Nums[0]; + + for(int i = 1; i < N; ++i) + { + Min = min(Min, Nums[i]); + Max = max(Max, Nums[i]); + + if(Max - Min > EstimateScore) + { + Count++; + Min = Nums[i]; + Max = Nums[i]; + } + } + + return Count <= M; + }; + + int Min = 0, Max = *max_element(Nums.begin(), Nums.end()); + int Score = Max; + while(Min <= Max) + { + int EstimateScore = (Min + Max) / 2; + if(IsValid(EstimateScore)) + { + Score = min(Score, EstimateScore); + Max = EstimateScore - 1; + } + else + { + Min = EstimateScore + 1; + } + } + + cout << Score; + + return 0; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 8ed2789..5268ec7 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -62,4 +62,5 @@ | 59차시 | 2024.8.01 | Greedy | [마법의 엘리베이터](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | [#210](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/210) | | 60차시 | 2024.8.05 | Implementation | [과제 진행하기](https://school.programmers.co.kr/learn/courses/30/lessons/176962) | [#213](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/213) | | 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) | \ No newline at end of file +| 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) | \ No newline at end of file