From dab9462d3dcfea9cee40865aab21f442dea5bf78 Mon Sep 17 00:00:00 2001 From: 9kyo-hwang Date: Mon, 19 Feb 2024 20:00:24 +0900 Subject: [PATCH] 28-9kyo-hwang --- .../1039 \352\265\220\355\231\230.cpp" | 55 +++++++++++ 9-kyo-hwang/README.md | 4 +- ...\354\204\240 \354\266\251\354\240\204.cpp" | 94 +++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 "9-kyo-hwang/Graph Traversal/1039 \352\265\220\355\231\230.cpp" create mode 100644 "9-kyo-hwang/Simulation/SWEA 5644 \353\254\264\354\204\240 \354\266\251\354\240\204.cpp" diff --git "a/9-kyo-hwang/Graph Traversal/1039 \352\265\220\355\231\230.cpp" "b/9-kyo-hwang/Graph Traversal/1039 \352\265\220\355\231\230.cpp" new file mode 100644 index 0000000..2b4af49 --- /dev/null +++ "b/9-kyo-hwang/Graph Traversal/1039 \352\265\220\355\231\230.cpp" @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +using namespace std; + +string N; int K; +unordered_set Visited[11]; + +int DFS(string Num = N, int Depth = 0) +{ + if(Visited[Depth].find(stoi(Num)) != Visited[Depth].end()) + { + return -1; + } + else if(Depth == K) + { + return stoi(Num); + } + else + { + Visited[Depth].emplace(stoi(Num)); + + int MaxNum = -1; + for(int i = 0; i < N.size() - 1; ++i) + { + for(int j = i + 1; j < N.size(); ++j) + { + if(i == 0 && Num[j] == '0') + { + continue; + } + + string TmpNum = Num; + swap(TmpNum[i], TmpNum[j]); + + MaxNum = max(MaxNum, DFS(TmpNum, Depth + 1)); + } + } + + return MaxNum; + } +} + +int main() +{ + cin.tie(nullptr)->sync_with_stdio(false); + + cin >> N >> K; + + cout << DFS(); + + return 0; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index f80a106..235cbae 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -26,4 +26,6 @@ | 23차시 | 2024.1.24 | Disjoint Set | [표 병합](https://school.programmers.co.kr/learn/courses/30/lessons/150366) | [#81](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/81) | | 24차시 | 2024.1.28 | Tree | [표현 가능한 이진트리](https://school.programmers.co.kr/learn/courses/30/lessons/150367) | [#92](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/92) | | 25차시 | 2024.2.8 | Brute Force | [조이스틱](https://school.programmers.co.kr/learn/courses/30/lessons/42860) | [#99](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/99) | -| 26차시 | 2024.2.11 | Brute Force | [주사위 고르기](https://school.programmers.co.kr/learn/courses/30/lessons/258709) | [#104](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/104) | \ No newline at end of file +| 26차시 | 2024.2.11 | Brute Force | [주사위 고르기](https://school.programmers.co.kr/learn/courses/30/lessons/258709) | [#104](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/104) | +| 27차시 | 2024.2.14 | Graph Traversal | [1039 교환](https://www.acmicpc.net/problem/1039) | [#105](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/105) | +| 28차시 | 2024.2.19 | Simulation | [SWEA 5644 무선 충전](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRDL1aeugDFAUo&categoryId=AWXRDL1aeugDFAUo&categoryType=CODE&problemTitle=5644&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=&pageSize=10&pageIndex=1) | [#111](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/111) | \ No newline at end of file diff --git "a/9-kyo-hwang/Simulation/SWEA 5644 \353\254\264\354\204\240 \354\266\251\354\240\204.cpp" "b/9-kyo-hwang/Simulation/SWEA 5644 \353\254\264\354\204\240 \354\266\251\354\240\204.cpp" new file mode 100644 index 0000000..103b055 --- /dev/null +++ "b/9-kyo-hwang/Simulation/SWEA 5644 \353\254\264\354\204\240 \354\266\251\354\240\204.cpp" @@ -0,0 +1,94 @@ +#include +#include + +using namespace std; +using Loc = pair; + +#define x first +#define y second + +Loc operator+(const Loc &a, const Loc &b) { return {a.x + b.x, a.y + b.y}; } + +struct BC { + int Index, X, Y, C, P; + + BC() : Index(-1), X(-1), Y(-1), C(-1), P(-1) {} + BC(int inIndex, int inX, int inY, int inC, int inP) + : Index(inIndex), X(inX), Y(inY), C(inC), P(inP) {} + + [[nodiscard]] inline int D(const Loc &loc) const { + return abs(X - loc.x) + abs(Y - loc.y); + } +}; + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + const vector offset = {{}, {-1, 0}, {0, 1}, {1, 0}, {0, -1}}; + + int M, A; + vector aMvTrajectories, bMvTrajectories; + vector BCs; + Loc aLoc, bLoc; + + auto Input = [&]() { + cin >> M >> A; + aMvTrajectories.assign(M + 1, 0); + bMvTrajectories.assign(M + 1, 0); + BCs.assign(A, {}); + + for (int T = 1; T <= M; ++T) { + cin >> aMvTrajectories[T]; + } + for (int T = 1; T <= M; ++T) { + cin >> bMvTrajectories[T]; + } + + int bcCnt = 0; + for (auto &[Index, X, Y, C, P] : BCs) { + cin >> Y >> X >> C >> P; + Index = bcCnt++; + } + + aLoc = {1, 1}; + bLoc = {10, 10}; + }; + + auto Charge = [&]() { + int maxCharge = 0; + for (const auto &aBC : BCs) { + const int aDist = aBC.D(aLoc); + const int aAmt = aDist <= aBC.C ? aBC.P : 0; + + for (const auto &bBC : BCs) { + const int bDist = bBC.D(bLoc); + const int bAmt = bDist <= bBC.C ? bBC.P : 0; + + const int curCharge = + (aBC.Index != bBC.Index ? aAmt + bAmt : max(aAmt, bAmt)); + + maxCharge = max(maxCharge, curCharge); + } + } + return maxCharge; + }; + + auto Move = [&]() { + int totalCharge = 0; + for (int time = 0; time <= M; ++time) { + aLoc = aLoc + offset[aMvTrajectories[time]]; + bLoc = bLoc + offset[bMvTrajectories[time]]; + + totalCharge += Charge(); + } + return totalCharge; + }; + + int T; + cin >> T; + for (int tc = 1; tc <= T; ++tc) { + Input(); + cout << "#" << tc << " " << Move() << "\n"; + } + + return 0; +} \ No newline at end of file