본문 바로가기

파이썬59

2025 프로그래머스 코드챌린지 2차 예선 > 서버 증설 횟수 - Python, 구현 https://school.programmers.co.kr/learn/courses/30/lessons/389479 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr  코드 & 풀이 def solution(players, m, k): answer = 0 size = len(players) servers = [0] * size def server_expansion(need_server, start): for idx in range(k): if start + idx = m: need_server = (player // m) - s.. 2025. 2. 15.
2025 프로그래머스 코드챌린지 1차 예선 > 비밀 코드 해독 - Python, Combinations, & 연산 https://school.programmers.co.kr/learn/courses/30/lessons/388352#qna 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr  코드 & 풀이 from itertools import combinationsdef solution(n, q, ans): possible_code = list(combinations(range(1, n + 1), 5)) total_cnt = 0 for code in possible_code: make_code = True for i in range(len(q)): if.. 2025. 2. 14.
다익스트라(Dijkstra) - Python, heapq 코드import heapqimport sysdef dijkstra(graph, start): INF = float('inf') n = len(graph) distance = [INF] * n distance[start] = 0 pq = [] heapq.heappush(pq, (0, start)) # (거리, 정점) while pq: dist, now = heapq.heappop(pq) if distance[now]  과정  거리 배열 초기화: 시작 정점에서 모든 정점까지의 최단 거리를 무한(∞)으로 설정, 시작 정점의 거리는 0으로 설정우선순위 큐(Priority Queue) 사용: 시작 정점을 큐에 넣음 (우선순위 큐는 Python.. 2025. 2. 7.
미로 탈출 - Python, BFS https://school.programmers.co.kr/learn/courses/30/lessons/159993 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr  코드 & 풀이 from collections import dequedef move_target(maps, directs, start_x, start_y, target): visited = [[0] * len(row) for row in maps] queue = deque() queue.append([start_x, start_y]) visited[start_x][start_y] = 1 while queue:.. 2024. 12. 29.
숫자 카드 나누기 - Pyton, GCD, Reduce https://school.programmers.co.kr/learn/courses/30/lessons/135807 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr  코드 & 풀이 def gcd(num1, num2): while num2: num1, num2 = num2, num1%num2 return num1def find_gcd(nums): result = nums[0] for num in nums[1:]: result = gcd(result, num) if result == 1: break return res.. 2024. 12. 29.
시소 짝꿍 - Pyton, https://school.programmers.co.kr/learn/courses/30/lessons/152996# 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr  코드 & 풀이 from collections import Counterdef solution(weights): answer = 0 weights_count = Counter(weights) # 각 무게의 등장 횟수 기록 # 동일한 무게끼리 짝꿍이 되는 경우 for weight, count in weights_count.items(): if count > 1: answer += coun.. 2024. 12. 24.