CS/문제 풀이2023. 2. 2. 22:38미로 탈출 명령어

시도 했던 방법 - BFS (간만에 BFS 로 풀겠다고 마음먹는 바람에..) 결론 - 먼저 거리 계산해서 되나 안되나 확인후 변위량을 계산해서 d, l, r, u 써야 되는거 계산하고 남은 카운트에서 d, l를 먼저가서 (최대 (n,1)) 간다 다음에 그래도 카운트가 남으면 rlrlrlrlrl 를 반복한다. from collections import deque # def solution(n, m, x, y, r, c, k): # answer = '' # q = deque([(x,y,"", 0)]) # while q: # pos_x, pos_y, path, count = q.popleft() # print(pos_x, pos_y, path, count) # if count == k : # if pos_x ..

CS/문제 풀이2023. 1. 31. 20:41표현 가능한 이진트리

풀이 과정은 다음과 같다 들어온 숫자를 이진트리 노드 갯수 (2**N - 1) 형태의 이진수로 변경한다 ex) 42 -> 0101010 DFS 를 활용해 부모가 0인데 자식이 1인 노드를 찾는다. 있으면 return 0 없으면 return 1 import math def DFS(binary, parent): # print(binary, parent) if len(binary) == 1: if parent == 0 and int(binary) == 1: # print("return 0 " ) return 0 else : return 1 mid_index = math.floor(len(binary)/2) root = int(binary[mid_index]) if parent == 0 and root == 1..

CS/문제 풀이2023. 1. 30. 22:00인사고과

def solution(scores): answer = 0 if len(scores) == 1: return 1 wanho_score = scores[0][1] + scores[0][0] # sorted_scores = sorted(scores, key=lambda x : (-x[0], -x[1])) sorted_scores = sorted(scores, key=lambda x : (-x[0], x[1])) # before_attitude_score = sorted_scores[0][0] max_reputation_score = sorted_scores[0][1] incentive_list = [] for attitude_score, reputation_score in sorted_scores: if r..

프로그래머스 레벨 1 다 풀고
CS/문제 풀이2022. 8. 11. 19:18프로그래머스 레벨 1 다 풀고

코딩 테스트 쓰면 좋은 함수 map - map(function_name, list_name(=iterable) : iterable한 요소에 function을 적용시킨다. 주로 타입 캐스팅을 하는데 용이하게 사용했다. 예를 들면 int, str 등의 경우를 빠르게 코드를 작성할 수 있다. zip - 여러 iterable 한 객체를 for 문 돌릴 때 하나씩 꺼내온다, index를 통해 접근하는 것보다 직관적이다 for a,b,c in zip(a_list, b_list, c_list) : d = a+b+c print(d) split() - 문자열을 파싱할 때, 파라미터로 넣은 문자열을 기준으로 잘라서 iterable 한 객체를 반환한다. hello_string = "Hello World, nice to me..

CS/문제 풀이2022. 1. 21. 23:23프로그래머스 - 이중순위큐,k 번째 수

https://programmers.co.kr/learn/courses/30/lessons/42628 코딩테스트 연습 - 이중우선순위큐 programmers.co.kr import heapq class Double_heap: def __init__(self): self.maxheap = list() self.minheap = list() def push(self, number): heapq.heappush(self.maxheap, -number) heapq.heappush(self.minheap, number) def pop_max(self): if self.maxheap and self.minheap : max_out = -heapq.heappop(self.maxheap) self.minheap.rem..

image