본문 바로가기

BOJ 알고리즘 (패캠)/자료구조, 구현

(11)
1874번: 스택수열 (구현, 스택) - Fastcampus www.acmicpc.net/problem/1874 1874번: 스택 수열 1부터 n까지에 수에 대해 차례로 [push, push, push, push, pop, pop, push, push, pop, push, push, pop, pop, pop, pop, pop] 연산을 수행하면 수열 [4, 3, 6, 8, 7, 5, 2, 1]을 얻을 수 있다. www.acmicpc.net import sys def run(N, a): res = [] i, st = 1, [] # 스택 for x in a: while x >= i: st.append(i) res.append("+") i += 1 if st[-1] == x: st.pop() res.append("-") else: return ["NO"] return r..
2798번: 블랙잭 (구현, 반복) - Fastcampus www.acmicpc.net/problem/2798 2798번: 블랙잭 첫째 줄에 카드의 개수 N(3 ≤ N ≤ 100)과 M(10 ≤ M ≤ 300,000)이 주어진다. 둘째 줄에는 카드에 쓰여 있는 수가 주어지며, 이 값은 100,000을 넘지 않는다. 합이 M을 넘지 않는 카드 3장을 찾을 수 있� www.acmicpc.net def run(N, M, a): max_v = 0 for i in range(N): for j in range(i + 1, N): for k in range(j + 1, N): s = a[i] + a[j] + a[k] if s
2920번: 음계 (구현, 반복) - Fastcampus www.acmicpc.net/problem/2920 2920번: 음계 다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다. 1부터 8까지 차례대로 연주한다면 ascending, 8�� www.acmicpc.net def run(a): ascending = True descending = True for i in range(len(a) - 1): if a[i] > a[i + 1]: ascending = False elif a[i] < a[i + 1]: descending = False if ascending: return "ascending" elif descending: re..