본문 바로가기

컴퓨터/백준 문제풀이20

1759 암호만들기, 5719 거의 최단 경로, 1774 우주신과의 교감 1759 암호만들기, 5719 거의 최단 경로, 1774 우주신과의 교감 1759 암호만들기 # 첫번째 풀이 import copy result = [] string = [] visited = [] def combination(array, length, index): if len(string) == length: result.append(copy.deepcopy(string)) return for i in range(index, len(array)): if i in visited: continue string.append(array[i]) visited.append(i) combination(array, length, i+1) string.pop() visited.pop() vowels = ('a', 'e.. 2020. 10. 16.
1781 컵라면, 9663 N-Queen, 1987 알파벳 1781 컵라면, 9663 N-Queen, 1987 알파벳 1781 컵라면 import heapq n = int(input()) array = [] q = [] for _ in range(n): # take deadline, number of noodle and sorting x, y = map(int, input().split()) array.append((x, y)) array.sort() for i in array: # add noodles and if deadline over, delete minimum value in list a = i[0] heapq.heappush(q, i[1]) if a < len(q): heapq.heappop(q) print(sum(q)) - 두 원소 받아서 튜플로 정.. 2020. 10. 14.
1092 배, 2212 센서, 1461 도서관 1092 배, 2212 센서, 1461 도서관 1092 배 # 첫번째 풀이(시간 초과, 노는 크레인 생김) n = int(input()) # 크레인 개수 crane = list(map(int, input().split())) crane = sorted(crane, reverse=True) m = int(input()) # 박스 개수 box = list(map(int, input().split())) box = sorted(box) len_of_box = len(box) count = 0 if crane[0] box[len_of_box - 1]: len_of_box -= 1 count.. 2020. 10. 12.
5585 거스름돈, 1439 뒤집기, 2012 등수 매기기 5585 거스름돈, 1439 뒤집기, 2012 등수 매기기 5585 거스름돈 # 첫번째 풀이 money_list = [500, 100, 50, 10, 5, 1] money = int(input()) money = 1000 - money count = 0 for i in money_list: if money < i: continue else: count += money // i money = money % i print(count) # 두번째 풀이(더 간단하게) money = 1000 - int(input()) count = 0 for i in [500, 100, 50, 10, 5, 1]: count += money // i money %= i print(count) 1439 뒤집기 s = input() .. 2020. 10. 12.