본문 바로가기

분류 전체보기443

[프로그래머스 PCCP 모의고사 3번] 카페 확장 from collections import deque def solution(menu, order, k): answer = 0 queue = deque() for i in order: queue.append(menu[i]) answer = max(answer,len(queue)) time = k while queue: # queue[0]과 time을 비교(걸리는 시간과 남은 시간) if queue[0] time: queue[0] -= time break else: queue.popleft() break return answer 이번 문제는 Queue 자료구조를 사용하여 푸는 문제인데 문제의 조건이 조금 .. 2023. 11. 11.
[프로그래머스 PCCP 모의고사 2번] 신입사원 교육 import heapq def solution(ability,number): # 신입사원 2명 선발, 선발 후 같이 공부시킴 # 모든 신입사원의 능력치는 정수로 표현 # 2명이 같이 공부하면 서로의 능력을 흡수하여 두 신입사원의 능력치는 # '공부하기 전 두 사람의 능력치의 합'이 됨 # 교육 후 모든 신입사원의 능력치의 합을 최소화 # 최솟값을 pop하는 시간복잡도를 최소화 하기위해 heapq 사용 q = [] for item in ability: heapq.heappush(q,item) for i in range(number): a = heapq.heappop(q) b = heapq.heappop(q) heapq.heappush(q,a+b) heapq.heappush(q,a+b) return sum(q) 2023. 11. 11.
[프로그래머스 PCCP 모의고사 1번] 실습용 로봇 def solution(command): answer = [] # 로봇은 입력된 명령에 따라 x, y좌표를 이동 # G : 바라보는 방향으로 한칸 전진 # B : 바라보는 방향으로 한칸 후진 # 위, 오른, 아래, 왼 dx = [0,1,0,-1] dy = [1,0,-1,0] direction = 0 x,y = 0, 0 command = list(command) for com in command: if com == "R": direction = (direction + 1)%4 elif com == "L": if direction > 0: direction -= 1 else: direction = 3 elif com == "G": x += dx[direction] y += dy[direction] elif .. 2023. 11. 11.
[백준 7682번] 틱택토 7682번: 틱택토 입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 줄은 9개의 문자를 포함하며, 'X', 'O', '.' 중 하나이다. '.'은 빈칸을 의미하며, 9개의 문자는 게임판에서 제일 윗 줄 왼쪽부터의 순서이다. 입 www.acmicpc.net area = [["."]*3 for _ in range(3)] cases = set() def check_is_full(): is_full = True for i in range(3): for j in range(3): if area[i][j] == '.': is_full = False return is_full def check_end(): if check_is_full(): return True if (area[0][0] == area[0][1.. 2023. 10. 20.
[백준 1182번] 부분수열의 합 1182번: 부분수열의 합 첫째 줄에 정수의 개수를 나타내는 N과 정수 S가 주어진다. (1 ≤ N ≤ 20, |S| ≤ 1,000,000) 둘째 줄에 N개의 정수가 빈 칸을 사이에 두고 주어진다. 주어지는 정수의 절댓값은 100,000을 넘지 않는다. www.acmicpc.net n, s = map(int,input().split()) # N개의 정수로 이루어진 수열, 부분수열의 원소를 다 더한 값이 S가 되는 경우의 수 data = list(map(int,input().split())) count = 0 visited = [False]*n def dfs(total,index,depth): global count if total == s and depth != 0: count += 1 for i in .. 2023. 10. 20.
[백준 2589번] 보물섬 2589번: 보물섬 보물섬 지도를 발견한 후크 선장은 보물을 찾아나섰다. 보물섬 지도는 아래 그림과 같이 직사각형 모양이며 여러 칸으로 나뉘어져 있다. 각 칸은 육지(L)나 바다(W)로 표시되어 있다. 이 지도에서 www.acmicpc.net import sys from collections import deque input = sys.stdin.readline dx = [-1,1,0,0] dy = [0,0,-1,1] # L : 육지, W : 바다 max_value = float("-inf") n, m = map(int,input().split()) area = [list(input().rstrip()) for _ in range(n)] def bfs(x,y): global max_value visite.. 2023. 10. 20.