From 1adc4bd9681fd9782ddc26498dbd1c2024c5ff4a Mon Sep 17 00:00:00 2001 From: JSPark <48265129+pknujsp@users.noreply.github.com> Date: Mon, 4 Mar 2024 22:12:45 +0900 Subject: [PATCH] 2024-03-04 --- pknujsp/README.md | 45 ++++++++-------- ...64\353\223\234\352\262\214\354\236\204.py" | 53 +++++++++++++++++++ 2 files changed, 76 insertions(+), 22 deletions(-) create mode 100644 "pknujsp/\352\265\254\355\230\204/37-\354\271\264\353\223\234\352\262\214\354\236\204.py" diff --git a/pknujsp/README.md b/pknujsp/README.md index ab833635..571b70d7 100644 --- a/pknujsp/README.md +++ b/pknujsp/README.md @@ -1,26 +1,26 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -| :----: | :--------: | :-------------: | :-----------------------------------------------------------------------------------------------: | :--------------------------------------------------------: | -| 1차시 | 2023.10.07 | BRUTE_FORCE | [BOJ_1107](https://www.acmicpc.net/problem/1107) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/2) | -| 2차시 | 2023.10.09 | BRUTE_FORCE | [연속 부분 수열 합의 개수](https://school.programmers.co.kr/learn/courses/30/lessons/131701) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/5) | -| 3차시 | 2023.10.11 | SORT | [최솟값 만들기](https://school.programmers.co.kr/learn/courses/30/lessons/12941?language=python3) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/8) | -| 4차시 | 2023.10.13 | SORT | [튜플](https://school.programmers.co.kr/learn/courses/30/lessons/64065) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/9) | -| 5차시 | 2023.10.15 | 구현 | [괄호 변환](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/13) | -| 6차시 | 2023.10.17 | 탐색 | [쿼드압축 후 개수 세기](https://school.programmers.co.kr/learn/courses/30/lessons/68936) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/16) | -| 7차시 | 2023.10.19 | 탐색 | [무인도 여행](https://school.programmers.co.kr/learn/courses/30/lessons/154540) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/20) | -| 8차시 | 2023.10.21 | 탐색 | [거리두기 확인하기](https://school.programmers.co.kr/learn/courses/30/lessons/81302) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/22) | -| 9차시 | 2023.10.23 | 맵 | [스킬 트리](https://school.programmers.co.kr/learn/courses/30/lessons/49993) | [#25](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/25) | -| 10차시 | 2023.10.25 | 구현 | [수식 최대화](https://school.programmers.co.kr/learn/courses/30/lessons/67257) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/28) | -| 11차시 | 2023.10.27 | 리스트 | [영어 끝말잇기](https://school.programmers.co.kr/learn/courses/30/lessons/12981) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/30) | -| 12차시 | 2023.10.30 | 큐 | [이중우선순위큐](https://school.programmers.co.kr/learn/courses/30/lessons/42628) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/36) | -| 13차시 | 2023.11.01 | DP | [등굣길](https://school.programmers.co.kr/learn/courses/30/lessons/42898) | [#39](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/39) | -| 14차시 | 2023.11.03 | 맵 | [시소 짝꿍](https://school.programmers.co.kr/learn/courses/30/lessons/152996) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/43) | -| 15차시 | 2023.11.05 | 수학 | [예상 대진표](https://school.programmers.co.kr/learn/courses/30/lessons/12985) | [#47](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/47) | -| 16차시 | 2023.11.08 | 수학 | [숫자 변환하기](https://school.programmers.co.kr/learn/courses/30/lessons/154538) | [#51](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/51) | -| 17차시 | 2023.11.10 | 스택 | [짝지어 제거하기](https://school.programmers.co.kr/learn/courses/30/lessons/12973) | [#54](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/54) | -| 18차시 | 2023.11.13 | 구현 | [키패드 누르기](https://school.programmers.co.kr/learn/courses/30/lessons/67256) | [#60](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/60) | -| 19차시 | 2023.11.17 | 구현 | [실패율](https://school.programmers.co.kr/learn/courses/30/lessons/42889) | [#64](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/64) | +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | +| :----: | :--------: | :-------------: | :-----------------------------------------------------------------------------------------------: | :---------------------------------------------------------: | +| 1차시 | 2023.10.07 | BRUTE_FORCE | [BOJ_1107](https://www.acmicpc.net/problem/1107) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/2) | +| 2차시 | 2023.10.09 | BRUTE_FORCE | [연속 부분 수열 합의 개수](https://school.programmers.co.kr/learn/courses/30/lessons/131701) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/5) | +| 3차시 | 2023.10.11 | SORT | [최솟값 만들기](https://school.programmers.co.kr/learn/courses/30/lessons/12941?language=python3) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/8) | +| 4차시 | 2023.10.13 | SORT | [튜플](https://school.programmers.co.kr/learn/courses/30/lessons/64065) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/9) | +| 5차시 | 2023.10.15 | 구현 | [괄호 변환](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/13) | +| 6차시 | 2023.10.17 | 탐색 | [쿼드압축 후 개수 세기](https://school.programmers.co.kr/learn/courses/30/lessons/68936) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/16) | +| 7차시 | 2023.10.19 | 탐색 | [무인도 여행](https://school.programmers.co.kr/learn/courses/30/lessons/154540) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/20) | +| 8차시 | 2023.10.21 | 탐색 | [거리두기 확인하기](https://school.programmers.co.kr/learn/courses/30/lessons/81302) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/22) | +| 9차시 | 2023.10.23 | 맵 | [스킬 트리](https://school.programmers.co.kr/learn/courses/30/lessons/49993) | [#25](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/25) | +| 10차시 | 2023.10.25 | 구현 | [수식 최대화](https://school.programmers.co.kr/learn/courses/30/lessons/67257) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/28) | +| 11차시 | 2023.10.27 | 리스트 | [영어 끝말잇기](https://school.programmers.co.kr/learn/courses/30/lessons/12981) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/30) | +| 12차시 | 2023.10.30 | 큐 | [이중우선순위큐](https://school.programmers.co.kr/learn/courses/30/lessons/42628) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/36) | +| 13차시 | 2023.11.01 | DP | [등굣길](https://school.programmers.co.kr/learn/courses/30/lessons/42898) | [#39](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/39) | +| 14차시 | 2023.11.03 | 맵 | [시소 짝꿍](https://school.programmers.co.kr/learn/courses/30/lessons/152996) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/43) | +| 15차시 | 2023.11.05 | 수학 | [예상 대진표](https://school.programmers.co.kr/learn/courses/30/lessons/12985) | [#47](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/47) | +| 16차시 | 2023.11.08 | 수학 | [숫자 변환하기](https://school.programmers.co.kr/learn/courses/30/lessons/154538) | [#51](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/51) | +| 17차시 | 2023.11.10 | 스택 | [짝지어 제거하기](https://school.programmers.co.kr/learn/courses/30/lessons/12973) | [#54](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/54) | +| 18차시 | 2023.11.13 | 구현 | [키패드 누르기](https://school.programmers.co.kr/learn/courses/30/lessons/67256) | [#60](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/60) | +| 19차시 | 2023.11.17 | 구현 | [실패율](https://school.programmers.co.kr/learn/courses/30/lessons/42889) | [#64](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/64) | | 20차시 | 2023.11.20 | 문자열 | [옹알이 (2)](https://school.programmers.co.kr/learn/courses/30/lessons/133499) | [#70](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/70) | | 21차시 | 2023.11.23 | 맵 | [의상](https://school.programmers.co.kr/learn/courses/30/lessons/42578) | [#73](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/73) | | 22차시 | 2023.11.26 | 그리디 | [구명보트](https://school.programmers.co.kr/learn/courses/30/lessons/42885) | [#79](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/79) | @@ -37,4 +37,5 @@ | 33차시 | 2024.02.06 | 큐 | [철로](https://www.acmicpc.net/problem/13334) | [#132](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/132) | | 34차시 | 2024.02.12 | BFS | [이분 그래프](https://www.acmicpc.net/problem/1707) | [#135](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/135) | | 35차시 | 2024.02.18 | 그리디 | [선물할인](https://www.acmicpc.net/problem/25947) | [#137](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137) | -| 36차시 | 2024.02.21 | 이진탐색 | [휴게소 세우기](https://www.acmicpc.net/problem/1477) | [#143](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143) | \ No newline at end of file +| 36차시 | 2024.02.21 | 이진탐색 | [휴게소 세우기](https://www.acmicpc.net/problem/1477) | [#143](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143) | +| 37차시 | 2024.03.04 | 구현 | [n+1 카드게임](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#149](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/149) | \ No newline at end of file diff --git "a/pknujsp/\352\265\254\355\230\204/37-\354\271\264\353\223\234\352\262\214\354\236\204.py" "b/pknujsp/\352\265\254\355\230\204/37-\354\271\264\353\223\234\352\262\214\354\236\204.py" new file mode 100644 index 00000000..6f1f8396 --- /dev/null +++ "b/pknujsp/\352\265\254\355\230\204/37-\354\271\264\353\223\234\352\262\214\354\236\204.py" @@ -0,0 +1,53 @@ +def solution(coin, cards): + a = set(cards[:len(cards) // 3]) + b = set() + t = len(cards) + 1 + r = 1 + + for i in range(len(cards) // 3 + 1, len(cards), 2): + c1, c2 = cards[i - 1], cards[i] + b.add(c1) + b.add(c2) + + removed = False + # 현재 가지고 있는 카드 목록 중 n + 1이 가능한 경우 확인 + for x in list(a): + if t - x in a: + a.remove(t - x) + a.remove(x) + removed = True + break + + if removed: + r += 1 + continue + + # 코인으로 교환해서 얻을 수 있는 카드 중에서 n + 1이 되는 경우를 찾아야 함 + # 코인이 없으므로 종료 + if not coin: + break + + # `현재 갖고 있는 카드 + 얻을 수 있는 카드` = n + 1이 되는 경우를 확인 + for x in list(b): + if t - x in a: + a.remove(t - x) + b.remove(x) + removed = True + coin -= 1 + break + # 마지막 방법으로, 오직 교환으로 얻을 수 있는 카드 목록 중에서 n + 1이 되는 경우를 확인 + if not removed and coin >= 2: + for x in list(b): + if t - x in b: + b.remove(t - x) + b.remove(x) + removed = True + coin -= 2 + break + + # n + 1을 어떤 경우에도 못 만들면 종료 + if not removed: + break + r += 1 + + return r \ No newline at end of file