본문 바로가기

백준 & 프로그래머스52

프로그래머스 [PCCP 모의고사 #2] 2번 - 신입사원 교육 # 임무: 2명 선발해서 공부하기 + 능력치 최소화 # 항상 최소만 뽑는다면 => 능력치 최소화 import heapq def solution(ability, number): heapq.heapify(ability) for _ in range(number): new_ability = heapq.heappop(ability) + heapq.heappop(ability) heapq.heappush(ability, new_ability) heapq.heappush(ability, new_ability) return sum(ability) 2023. 12. 3.
프로그래머스 [PCCP 모의고사 #2] 1번 - 실습용 로봇.python def solution(command): com_dic = {'R': 1, 'L': -1} direction_list = [(0, 1), (1, 0), (0, -1), (-1, 0)] direction_cnt = 0 xy = [0,0] for com in command: if com in com_dic: direction_cnt += com_dic[com] if direction_cnt >= 4: direction_cnt = 0 elif direction_cnt 2023. 12. 3.
프로그래머스.[PCCP 모의고사 1] 4번.python 앞으로 priorityQueue절대 안씀ㅡㅡ heapq최고 import heapq def solution(program): # answer 배열 초기화 answer = [0 for _ in range(11)] # program을 호출 시각에 따라 정렬합니다. program.sort(key=lambda x: x[1]) # 최소 힙 wait_heap = [] # 변수 초기화 pro_cnt, end_pro_cnt, time, pro_size = 0, 0, 0, len(program) # 모든 프로그램이 끝날 때까지 반복 while end_pro_cnt != pro_size: # 시작 시간이 time 이하인 프로그램들을 대기열에 추가 while pro_cnt = progra.. 2023. 12. 2.
[PCCP 모의고사 #1] 3번 - 유전법칙 RR(4)라고 표기한건 [RR, RR, RR, RR]을 의미 그냥 해당 seq(유전자 형질) 갯수 나타낸것입니다. 처음에 문자 그대로 그냥 점화식으로 풀었는데 시간초과 떠서 다시품 dp[n] = [ RR(4**(n-2)), dp[n-1], dp[n-1], rr(4**(n-2))] (n>1) 보면 앞에 RR과 맨뒤 rr은 갯수가 많으니까 ["RR", "RR", "RR", "RR", ....] 이렇게 문자 그대로 list에 넣고 점화식 돌리면 아주 오래걸림 보통 그냥해서 시간초과 나면 비슷하거나 같은거 끼리 묶으면 해결 가능 ex) ["RR", "RR", "RR", "RR"] => RR(4) 그래서 숫자로 대체 1 세대 => Rr => 나중에 예외처리 해줌 2 세대 => RR(1), Rr(2), rr(1) .. 2023. 11. 30.
프로그래머스.붕대감기.java import java.util.*; import java.io.*; // defalt bandage[1] 만큼 회복 else -공격 // bandage[0]초 => bandage[2] 추가 회복 // [시전 시간, 초당 회복량, 추가 회복량] 최대 100 // [공격 시간, 피해량] 이미 정렬 class Solution{ public int solution(int[] bandage, int health, int[][] attacks){ int attackCnt = 0,heelCnt = 0; int firstAttack = attacks[0][0]; int lastAttack = attacks[attacks.length - 1][0]; int maxHealth = health; for(int t = fir.. 2023. 11. 28.
프로그래머스.주차 요금 계산.py 나중에 class로도 풀어보기 def solution(fees, records): answer = [] # 차량별 정보로 바꾸기 car_dic, car_time_dic = dict(), dict() for rec in records: time_str, num, io = rec.split() h, m = map(int, time_str.split(':')) time = h * 60 + m if io == 'IN': car_dic[num] = time elif io == 'OUT': car_dic[num] = time - car_dic[num] if num in car_time_dic: car_time_dic[num] += car_dic[num] else: car_time_dic[num] = car_dic[.. 2023. 11. 28.