From 47b5fe66487ce84916106788f0d02148938969d8 Mon Sep 17 00:00:00 2001 From: Do Hyeon Seok Date: Wed, 30 Apr 2025 13:22:11 +0900 Subject: [PATCH] 2025-04-30 --- dohyeondol1/README.md | 7 ++- .../9-dohyeondol1.cpp" | 43 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 "dohyeondol1/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/9-dohyeondol1.cpp" diff --git a/dohyeondol1/README.md b/dohyeondol1/README.md index 586986f..e888324 100644 --- a/dohyeondol1/README.md +++ b/dohyeondol1/README.md @@ -9,4 +9,9 @@ | 5차시 | 2025.04.02 | DFS & BFS | [DFS와 BFS](https://www.acmicpc.net/problem/1260)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/18| | 6차시 | 2025.04.05 | DP | [평범한 배낭](https://www.acmicpc.net/problem/12865)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/22| | 7차시 | 2025.04.08 | 트리 | [트리 순회](https://www.acmicpc.net/problem/1991)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/26| - --- \ No newline at end of file +<<<<<<< Updated upstream + --- +======= + | 8차시 | 2025.04.11 | 덱 | [회전하는 큐](https://www.acmicpc.net/problem/1021)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/32| + | 9차시 | 2025.04.30 | 그리디 알고리즘 | [체육복](https://school.programmers.co.kr/learn/courses/30/lessons/42862)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/33| +>>>>>>> Stashed changes diff --git "a/dohyeondol1/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/9-dohyeondol1.cpp" "b/dohyeondol1/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/9-dohyeondol1.cpp" new file mode 100644 index 0000000..8b93b6c --- /dev/null +++ "b/dohyeondol1/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/9-dohyeondol1.cpp" @@ -0,0 +1,43 @@ +#include +#include +#include +using namespace std; + +int solution(int n, vector lost, vector reserve) { + int answer = 0; + + answer += n - lost.size(); + sort(lost.begin(), lost.end()); + sort(reserve.begin(), reserve.end()); + + for (int i = 0; i < lost.size(); ) { + bool found = false; + for (int j = 0; j < reserve.size(); j++) { + if (lost[i] == reserve[j]) { + lost.erase(lost.begin() + i); + reserve.erase(reserve.begin() + j); + found = true; + answer++; + break; + } + } + if (!found) i++; + } + + for(int i = 0; i < lost.size(); i++) { + for(int j = 0; j < reserve.size(); j++) { + if((lost[i]-1) == reserve[j]) { + reserve.erase(reserve.begin()); + answer++; + break; + } + else if(lost[i]+1 == reserve[j]) { + reserve.erase(reserve.begin()); + answer++; + break; + } + } + } + + return answer; +} \ No newline at end of file