From c3e3e9e2dd0e50494ecd13dd56f44154cb032ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=88=98=ED=98=84?= Date: Fri, 13 Sep 2024 17:23:59 +0900 Subject: [PATCH 1/2] =?UTF-8?q?2024-09-13=20=EB=8F=99=EC=A0=84=200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- suhyun113/README.md | 3 ++- .../16-suhyun113.py" | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 "suhyun113/\352\267\270\353\246\254\353\224\224/16-suhyun113.py" diff --git a/suhyun113/README.md b/suhyun113/README.md index ffc876a..4acf66a 100644 --- a/suhyun113/README.md +++ b/suhyun113/README.md @@ -13,4 +13,5 @@ | 9차시 | 2024.05.28 | 다익스트라 | [최소비용 구하기](https://www.acmicpc.net/problem/1916) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/33) | | 10차시 | 2024.07.13 | 플로이드-워셜 | [플로이드](https://www.acmicpc.net/problem/11404) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/36) | | 11차시 | 2024.07.16 | BFS | [연구소](https://www.acmicpc.net/problem/14502) | [#39](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/39) | -| 12차시 | 2024.07.24 | 이분 탐색 | [나무 자르기](https://www.acmicpc.net/problem/2805) | [#42](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/42) | \ No newline at end of file +| 12차시 | 2024.07.24 | 이분 탐색 | [나무 자르기](https://www.acmicpc.net/problem/2805) | [#42](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/42) | +| 16차시 | 2024.09.13 | 그리디 | [동전 0](https://www.acmicpc.net/problem/11047) | [#49](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/49) | \ No newline at end of file diff --git "a/suhyun113/\352\267\270\353\246\254\353\224\224/16-suhyun113.py" "b/suhyun113/\352\267\270\353\246\254\353\224\224/16-suhyun113.py" new file mode 100644 index 0000000..d962ae3 --- /dev/null +++ "b/suhyun113/\352\267\270\353\246\254\353\224\224/16-suhyun113.py" @@ -0,0 +1,19 @@ +# 11047 : 동전 0 + +# 동전의 종류와 목표 금액을 입력받아 최소 동전 개수를 계산하는 함수 +def min_coins(n, k, coins): + count = 0 # 동전 개수를 세기 위한 변수 + for coin in reversed(coins): # 동전의 종류를 큰 것부터 작은 것 순으로 탐색 + if k == 0: # 목표 금액이 0이면 더 이상 동전을 사용할 필요 없음 + break + count += k // coin # 현재 동전으로 만들 수 있는 최대 개수 추가 + k %= coin # 남은 금액 업데이트 + return count # 최소 동전 개수 반환 + +# 입력 받기 +n, k = map(int, input().split()) # 동전의 종류(n)와 목표 금액(k) 입력 +coins = [int(input()) for _ in range(n)] # 동전의 종류 입력 + +# 최소 동전 개수 계산 및 출력 +result = min_coins(n, k, coins) +print(result) \ No newline at end of file From 12fb0e155b082a4c757b8e8bea53e16c807d77e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=88=98=ED=98=84?= Date: Sun, 22 Sep 2024 02:26:36 +0900 Subject: [PATCH 2/2] =?UTF-8?q?2024-09-22=20=EC=8A=A4=ED=83=9D=20=EC=88=98?= =?UTF-8?q?=EC=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- suhyun113/README.md | 3 +- .../\354\212\244\355\203\235/17-suhyun113.py" | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 "suhyun113/\354\212\244\355\203\235/17-suhyun113.py" diff --git a/suhyun113/README.md b/suhyun113/README.md index 4acf66a..2525a98 100644 --- a/suhyun113/README.md +++ b/suhyun113/README.md @@ -14,4 +14,5 @@ | 10차시 | 2024.07.13 | 플로이드-워셜 | [플로이드](https://www.acmicpc.net/problem/11404) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/36) | | 11차시 | 2024.07.16 | BFS | [연구소](https://www.acmicpc.net/problem/14502) | [#39](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/39) | | 12차시 | 2024.07.24 | 이분 탐색 | [나무 자르기](https://www.acmicpc.net/problem/2805) | [#42](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/42) | -| 16차시 | 2024.09.13 | 그리디 | [동전 0](https://www.acmicpc.net/problem/11047) | [#49](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/49) | \ No newline at end of file +| 16차시 | 2024.09.13 | 그리디 | [동전 0](https://www.acmicpc.net/problem/11047) | [#49](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/49) | +| 17차시 | 2024.09.22 | 스택 | [스택 수열](https://www.acmicpc.net/problem/1874) | [#53](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/53) | \ No newline at end of file diff --git "a/suhyun113/\354\212\244\355\203\235/17-suhyun113.py" "b/suhyun113/\354\212\244\355\203\235/17-suhyun113.py" new file mode 100644 index 0000000..a0f62fe --- /dev/null +++ "b/suhyun113/\354\212\244\355\203\235/17-suhyun113.py" @@ -0,0 +1,29 @@ +# 1874 : 스택 수열 + +n = int(input()) # 수열의 크기 +sequence = [int(input()) for _ in range(n)] # 주어진 수열 + +stack = [] +result = [] +current = 1 # 스택에 넣을 숫자 +possible = True + +for num in sequence: + # 현재 숫자보다 수열에서 필요한 숫자가 크거나 같을 때까지 push + while current <= num: + stack.append(current) + result.append('+') + current += 1 + + # 스택의 최상단이 num과 같다면 pop + if stack and stack[-1] == num: + stack.pop() + result.append('-') + else: + possible = False + break + +if possible: + print("\n".join(result)) +else: + print("NO") \ No newline at end of file