diff --git "a/9-kyo-hwang/Brute Force/2024 KAKAO WINTER INTERNSHIP \353\254\270\354\240\234 3 \354\243\274\354\202\254\354\234\204 \352\263\240\353\245\264\352\270\260.cpp" "b/9-kyo-hwang/Brute Force/2024 KAKAO WINTER INTERNSHIP \353\254\270\354\240\234 3 \354\243\274\354\202\254\354\234\204 \352\263\240\353\245\264\352\270\260.cpp" new file mode 100644 index 0000000..518173e --- /dev/null +++ "b/9-kyo-hwang/Brute Force/2024 KAKAO WINTER INTERNSHIP \353\254\270\354\240\234 3 \354\243\274\354\202\254\354\234\204 \352\263\240\353\245\264\352\270\260.cpp" @@ -0,0 +1,71 @@ +#include +#include +#include +#include + +using namespace std; + +void CountEachComboSums(const vector>& Dices, const vector& SelectedDices, unordered_map& DiceComboMap, int ComboSum = 0, int DiceIndex = 0) +{ + if(DiceIndex == SelectedDices.size()) + { + DiceComboMap[ComboSum] += 1; + return; + } + + for(const int& DicePip : Dices[SelectedDices[DiceIndex]]) + { + CountEachComboSums(Dices, SelectedDices, DiceComboMap, ComboSum + DicePip, DiceIndex + 1); + } +} + +vector solution(vector> Dice) +{ + const int NumDice = Dice.size(); + vector IsADice(NumDice / 2, false); + IsADice.insert(IsADice.end(), NumDice / 2, true); + + int MaxCntOfAWins = 0; + vector Answer; + do + { + vector A, B; + for(int i = 0; i < NumDice; ++i) + { + IsADice[i] ? A.emplace_back(i) : B.emplace_back(i); + } + + unordered_map AComboMap, BComboMap; + CountEachComboSums(Dice, A, AComboMap); + CountEachComboSums(Dice, B, BComboMap); + + vector> AComboVector(AComboMap.begin(), AComboMap.end()); + vector> BComboVector(BComboMap.begin(), BComboMap.end()); + + sort(AComboVector.begin(), AComboVector.end()); + sort(BComboVector.begin(), BComboVector.end()); + + int CntOfAWins = 0; + for(const auto& [AComboSum, AComboCnt] : AComboVector) + { + for(const auto& [BComboSum, BComboCnt] : BComboVector) + { + if(BComboSum >= AComboSum) + { + break; + } + + CntOfAWins += AComboCnt * BComboCnt; + } + } + + if(CntOfAWins > MaxCntOfAWins) + { + MaxCntOfAWins = CntOfAWins; + Answer = A; + } + } while(next_permutation(IsADice.begin(), IsADice.end())); + + transform(Answer.begin(), Answer.end(), Answer.begin(), [](int& i) { return i + 1; }); + return Answer; +} \ No newline at end of file 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..d7064ef --- /dev/null +++ "b/9-kyo-hwang/Graph Traversal/1039 \352\265\220\355\231\230.cpp" @@ -0,0 +1,49 @@ +#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/Prefix Sum/2022 KAKAO BLIND RECRUITMENT \355\214\214\352\264\264\353\220\230\354\247\200 \354\225\212\354\235\200 \352\261\264\353\254\274.cpp" "b/9-kyo-hwang/Prefix Sum/2022 KAKAO BLIND RECRUITMENT \355\214\214\352\264\264\353\220\230\354\247\200 \354\225\212\354\235\200 \352\261\264\353\254\274.cpp" new file mode 100644 index 0000000..e8b9f7c --- /dev/null +++ "b/9-kyo-hwang/Prefix Sum/2022 KAKAO BLIND RECRUITMENT \355\214\214\352\264\264\353\220\230\354\247\200 \354\225\212\354\235\200 \352\261\264\353\254\274.cpp" @@ -0,0 +1,86 @@ +#include +#include + +using namespace std; + +struct FSkill +{ + int Type, R1, C1, R2, C2, Degree; + + FSkill(const vector& InSkill) : Type(InSkill[0]), R1(InSkill[1]), C1(InSkill[2]), R2(InSkill[3]), C2(InSkill[4]), Degree(InSkill[5]) { } +}; + +enum class ESkillType +{ + NONE, + ATTACK, + HEAL, +}; + +vector> GetWeightMatrix(const int N, const int M, const vector>& InSkills) +{ + vector WeightMatrix(N + 1, vector(M + 1, 0)); + for(const vector& InSkill : InSkills) + { + FSkill Skill(InSkill); + if(Skill.Type == static_cast(ESkillType::ATTACK)) + { + WeightMatrix[Skill.R1][Skill.C1] -= Skill.Degree; + WeightMatrix[Skill.R2 + 1][Skill.C2 + 1] -= Skill.Degree; + + WeightMatrix[Skill.R1][Skill.C2 + 1] += Skill.Degree; + WeightMatrix[Skill.R2 + 1][Skill.C1] += Skill.Degree; + } + else if(Skill.Type == static_cast(ESkillType::HEAL)) + { + WeightMatrix[Skill.R1][Skill.C1] += Skill.Degree; + WeightMatrix[Skill.R2 + 1][Skill.C2 + 1] += Skill.Degree; + + WeightMatrix[Skill.R1][Skill.C2 + 1] -= Skill.Degree; + WeightMatrix[Skill.R2 + 1][Skill.C1] -= Skill.Degree; + } + } + + for(int i = 0; i <= N; ++i) + { + for(int j = 0; j < M; ++j) + { + WeightMatrix[i][j + 1] += WeightMatrix[i][j]; + } + } + + for(int j = 0; j <= M; ++j) + { + for(int i = 0; i < N; ++i) + { + WeightMatrix[i + 1][j] += WeightMatrix[i][j]; + } + } + + return WeightMatrix; +} + +int solution(vector> Board, vector> Skills) +{ + const int N = Board.size(), M = Board[0].size(); + vector> WeightMatrix = GetWeightMatrix(N, M, Skills); + + for(int i = 0; i < N; ++i) + { + for(int j = 0; j < M; ++j) + { + Board[i][j] += WeightMatrix[i][j]; + } + } + + int Answer = 0; + for(const vector& Row : Board) + { + for(const int& Col : Row) + { + Answer += (Col > 0); + } + } + + return Answer; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index f80a106..8b68b69 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -26,4 +26,7 @@ | 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) | +| 29차시 | 2024.2.22 | Prefix Sum | [파괴되지 않은 건물](https://school.programmers.co.kr/learn/courses/30/lessons/92344) | [#114](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/114) | 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 diff --git "a/Dolchae/DFS&BFS/2644 \354\264\214\354\210\230\352\263\204\354\202\260.py" "b/Dolchae/DFS&BFS/2644 \354\264\214\354\210\230\352\263\204\354\202\260.py" new file mode 100644 index 0000000..d515960 --- /dev/null +++ "b/Dolchae/DFS&BFS/2644 \354\264\214\354\210\230\352\263\204\354\202\260.py" @@ -0,0 +1,28 @@ +n = int(input()) +a,b = map(int, input().split()) +node_num = int(input()) +graph = [[] for _ in range(n+1)] +visited = [False] * (n+1) +result = [] + +for _ in range(node_num): + x, y = map(int, input().split()) + graph[x].append(y) + graph[y].append(x) + +def dfs(v, num): + num += 1 + visited[v] = True + + if v == b: + result.append(num) + + for i in graph[v]: + if not visited[i]: + dfs(i, num) + +dfs(a, 0) +if len(result) == 0: + print(-1) +else: + print(result[0]-1) \ No newline at end of file diff --git a/Dolchae/README.md b/Dolchae/README.md index 2df4037..bda8bb4 100644 --- a/Dolchae/README.md +++ b/Dolchae/README.md @@ -28,4 +28,7 @@ | 24차시| 2024.01.29 | 수학 | [2108 통계학](https://www.acmicpc.net/problem/2108) | [#87](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/87) | | 25차시| 2024.02.01 | DP | [1535 안녕](https://www.acmicpc.net/problem/1535) | [#89](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/89) | | 26차시| 2024.02.05 | 구현 | [18110 solved.ac](https://www.acmicpc.net/problem/18110) | [#93](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/93) | -| 27차시| 2024.02.08 | 정렬 | [1302 베스트셀러](https://www.acmicpc.net/problem/1302) | [#97](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/97) | \ No newline at end of file +| 27차시| 2024.02.08 | 정렬 | [1302 베스트셀러](https://www.acmicpc.net/problem/1302) | [#97](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/97) | +| 28차시| 2024.02.15 | 이진 탐색 | [6236 용돈 관리](https://www.acmicpc.net/problem/1302) | [#107](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/107) | +| 29차시| 2024.02.19 | 브루트포스 | [2961 도영이가 만든 맛있는 음식](https://www.acmicpc.net/problem/2961) | [#109](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/109) | +| 30차시| 2024.02.22 | DFS | [2644 촌수계산](https://www.acmicpc.net/problem/2961) | [#112](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/112) | \ No newline at end of file diff --git "a/Dolchae/\353\270\214\353\243\250\355\212\270\355\217\254\354\212\244/2961 \353\217\204\354\230\201\354\235\264\352\260\200 \353\247\214\353\223\240 \353\247\233\354\236\210\353\212\224 \354\235\214\354\213\235n.py" "b/Dolchae/\353\270\214\353\243\250\355\212\270\355\217\254\354\212\244/2961 \353\217\204\354\230\201\354\235\264\352\260\200 \353\247\214\353\223\240 \353\247\233\354\236\210\353\212\224 \354\235\214\354\213\235n.py" new file mode 100644 index 0000000..7404c9e --- /dev/null +++ "b/Dolchae/\353\270\214\353\243\250\355\212\270\355\217\254\354\212\244/2961 \353\217\204\354\230\201\354\235\264\352\260\200 \353\247\214\353\223\240 \353\247\233\354\236\210\353\212\224 \354\235\214\354\213\235n.py" @@ -0,0 +1,23 @@ +import sys +from itertools import combinations +input = sys.stdin.readline + +n = int(input()) + +ingrid = [[0 for _ in range(2)] for _ in range(n)] +for i in range(n): + ingrid[i][0],ingrid[i][1] = map(int,input().split()) + +ans = abs(ingrid[0][0] - ingrid[0][1]) +for i in range(1,n+1): #1 + for comb in combinations(ingrid,i): #2 + print(comb) + sour, bitter = 1,0 + for j in range(i): #3 + sour *= comb[j][0] + bitter += comb[j][1] + now_diff = abs(sour-bitter) + if now_diff < ans: + ans = now_diff + +print(ans) diff --git "a/Dolchae/\354\235\264\354\247\204 \355\203\220\354\203\211/6236 \354\232\251\353\217\210 \352\264\200\353\246\254.py" "b/Dolchae/\354\235\264\354\247\204 \355\203\220\354\203\211/6236 \354\232\251\353\217\210 \352\264\200\353\246\254.py" new file mode 100644 index 0000000..6c19126 --- /dev/null +++ "b/Dolchae/\354\235\264\354\247\204 \355\203\220\354\203\211/6236 \354\232\251\353\217\210 \352\264\200\353\246\254.py" @@ -0,0 +1,36 @@ +import sys + +input = sys.stdin.readline + +n, m = map(int, input().split()) + +money = [] +for _ in range(n): + money.append(int(input())) + +start = max(money) +end = sum(money) + +ans = 0 +while start <= end: + mid = (start + end) // 2 + + total = 0 + cnt = 0 + for x in money: + if total + x <= mid: + total += x + else: + cnt += 1 + total = 0 + total += x + if total: + cnt += 1 + + if cnt > m: + start = mid + 1 + else: + end = mid - 1 + ans = mid + +print(ans) \ No newline at end of file diff --git "a/xxubin04/DP/2502_\353\226\241 \353\250\271\353\212\224 \355\230\270\353\236\221\354\235\264.py" "b/xxubin04/DP/2502_\353\226\241 \353\250\271\353\212\224 \355\230\270\353\236\221\354\235\264.py" new file mode 100644 index 0000000..b531878 --- /dev/null +++ "b/xxubin04/DP/2502_\353\226\241 \353\250\271\353\212\224 \355\230\270\353\236\221\354\235\264.py" @@ -0,0 +1,15 @@ +input = open(0).readline + +days, tteok_num = map(int, input().split()) + +for i in range(1, tteok_num): + for j in range(i, tteok_num): + a = i; b = j + for k in range(2, days): + temp = a + b + a = b + b = temp + + if temp == tteok_num: + print(f"{i}\n{j}") + exit() \ No newline at end of file diff --git a/xxubin04/README.md b/xxubin04/README.md index 6717074..d7af60b 100644 --- a/xxubin04/README.md +++ b/xxubin04/README.md @@ -31,4 +31,4 @@ | 27차시 | 2024.02.08 | 수학 | [2885]초콜릿 식사 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/98 | | 28차시 | 2024.02.15 | 이진탐색 | [2805]나무 자르기 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/108 | | 29차시 | 2024.02.19 | DP | [2502]떡 먹는 호랑이 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/110 | -| 30차시 | 2024.02.22 | BFS | [14562]태권왕 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/113 | +| 30차시 | 2024.02.22 | BFS | [14562]태권왕 | https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/113 | \ No newline at end of file