[ 알고리즘 ]

    [프로그래머스] 두 큐 합 같게 만들기

    [프로그래머스] 두 큐 합 같게 만들기

    📌문제 https://school.programmers.co.kr/learn/courses/30/lessons/118667 🎖️난이도 Level 2 ✔️풀이 from collections import deque def solution(queue1, queue2): # 예외처리 sum1, sum2 = sum(queue1), sum(queue2) total = sum1 + sum2 if total % 2 == 1 or max(queue1) > total/2 or max(queue2) > total/2: return -1 if sum1 == sum2: return 0 total = int(total/2) q1, q2 = deque(queue1), deque(queue2) cnt = 0 # greedy whil..

    [프로그래머스] 프렌즈4블록

    [프로그래머스] 프렌즈4블록

    📌문제 https://school.programmers.co.kr/learn/courses/30/lessons/17679?language=python3 🎖️난이도 Level 2 ✔️풀이 from collections import deque def check2x2(i, j, m, n, board): if i+1 in range(0, m) and j+1 in range(0, n): if board[i][j] == board[i][j+1] == board[i+1][j] == board[i+1][j+1]: return True return False def replaceTo0(board, visited): for x, y in visited: board[x][y] = 0 def pop_board(m, n, bo..

    [프로그래머스] 거리두기 확인하기

    [프로그래머스] 거리두기 확인하기

    📌문제 https://programmers.co.kr/learn/courses/30/lessons/43164 🎖️난이도 Level 2 ✔️풀이 from collections import deque def bfs(graph): dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] for i in range(5): for j in range(5): if graph[i][j] == 'P': queue = deque() queue.append((i, j, 0)) visited = set() visited.add((i, j)) while queue: x, y, d = queue.popleft() for k in range(4): nx = x + dx[k] ny = y + dy[k] nd = d + ..

    [백준] 2667. 단지번호붙이기

    [백준] 2667. 단지번호붙이기

    📌문제 https://www.acmicpc.net/problem/2667 🎖️난이도 ✔️풀이 from collections import deque n = int(input()) graph = [list(map(int, list(input()))) for _ in range(n)] dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] danji_num = 0 house_num_list = [] for i in range(n): for j in range(n): if graph[i][j] == 1: # bfs queue = deque() queue.append([i, j]) # 첫 시작점의 nx, ny부터 cnt += 1 해주므로, cnt = 1부터 시작 cnt = 1 graph[i][j] =..

    [COS PRO 1급 Python] 1차 기출 문제 풀이

    COS PRO 1급 기출문제 - Python - 구름EDU YBMIT에서 시행하는 COS Pro 자격증으로 기출문제를 직접 풀어볼 수 있는 실습 위주의 강좌입니다. edu.goorm.io 문제 1) 음식전문점 운영 class DeliveryStore(metaclass=ABCMeta): @abstractmethod def set_order_list(self, order_list): pass @abstractmethod def get_total_price(self): pass class Food: def __init__(self, name, price): self.name = name self.price = price class PizzaStore(DeliveryStore): # 빈칸 채우기 (상속) def..