일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- 우선순위큐
- 서브쿼리
- 누적합
- 구현
- 다이나믹프로그래밍
- 그래프 탐색
- GROUP BY
- join
- 플로이드-워셜
- 브루트포스
- 에라토스테네스의 체
- 트리
- 그리디
- 크루스칼
- DFS
- 분할정복
- 그래프 이론
- MST
- 다이나믹 프로그래밍
- 시뮬레이션
- 다시
- BFS
- 해시
- 재귀
- DP
- 수학
- 투포인터
- 다익스트라
- 백트래킹
- 자료구조
- Today
- Total
목록전공/프로그래머스 (34)
기록하고 까먹지 말기

날짜 : 2023. 09. 25 사용 언어 : python 문제 코드 def solution(s): def change(a): # a를 2진수로 리턴 tmp = list() while a > 0: tmp.append(str(a % 2)) a = a // 2 tmp.sort(reverse=True) string = "" for i in tmp: string += i return string cnt, zero = 0, 0 while True: if s == "1": break t = 0 # 0의 개수 # 0 제거 cnt += 1 for i in s: if i == "0": t += 1 zero += t # 제거된 0의 개수 가산 s = change(len(s)-t) answer = [cnt, zero] re..

날짜 : 2023. 09. 13 사용 언어 : python 문제 코드 def dfs(row, depth): cnt = 0 # 개수 저장용 if depth == len(row): # 마지막 행까지 도달 return 1 for i in range(len(row)): row[depth] = i # 해당 row에서 퀸을 위치시켰을 때 for j in range(depth): if row[depth] == row[j] : break # 같은 열인지 체크 if abs(row[depth] - row[j]) == (depth - j): break # 대각선인지 체크 else: cnt += dfs(row, depth+1) return cnt def solution(n): row = [0] * n # 리스트 row의 i번..

날짜 : 2023. 09. 11 사용 언어 : python 문제 코드 def solution(a, b): a.sort() b.sort(reverse=True) answer = 0 for i in range(len(a)): answer += a[i] * b[i] return answer 풀이 - 두 개의 배열 a, b를 각각 오름차순, 내림차순으로 정렬한다. - 그 다음 각각의 인덱스에 맞게 a와 b의 원소를 곱하여 더한다. 알게된 점 - 곱셈은 값이 지수방식으로 커지기 땜누에 인자를 최소한으로 만들어 주는 것이 메인이었다. - 다시 코테를 시작한 만큼 열심히 풀어야겠다. 참고 사이트 -

날짜 : 2023. 06. 07 사용 언어 : python 문제 코드 # 레버 위치 찾기 -> 레버까지의 거리 구하기(BFS) -> 레버에서 출구까지 거리 구하기(BFS) from collections import deque def solution(maps): m = len(maps) n = len(maps[0]) i, j = 0, 0 flag = False for i in range(m): for j in range(n): if maps[i][j] == "S": r, c = i, j break queue = deque() queue.append([r, c]) visited = [[-1] * n for _ in range(m)] visited[r][c] = 0 dx = [0, 0, 1, -1] dy = ..

날짜 : 2023. 05. 30 사용 언어 : python 문제 코드 from collections import deque def solution(rectangle, a, b, itemX, itemY): graph = [[-1] * 102 for _ in range(102)] for r in rectangle: x1, y1, x2, y2 = r x1 *= 2 # 2배처리 y1 *= 2 x2 *= 2 y2 *= 2 for i in range(x1, x2 + 1): for j in range(y1, y2 + 1): if x1 < i < x2 and y1 < j < y2: # 테두리 채우기 graph[i][j] = -2 # 내부 elif graph[i][j] != -2: # 테두리 graph[i][j] = 0..

날짜 : 2023. . 사용 언어 : python 문제 코드 from collections import deque def solution(n, edge): queue = deque() graph = [[] for _ in range(n+1)] for s, e in edge: graph[s].append(e) graph[e].append(s) visited = [False] * (n + 1) # 미방문 : False / 방문 : 방문거리 visited[1] = 1 # 맨 처음 노드(0) queue.append(1) while queue: now = queue.popleft() # 현재 노드 for i in graph[now]: # 현재 노드와 연결된 노드 탐색 if visited[i] == False: #..

날짜 : 2023. 05. 29 사용 언어 : python 문제 코드 from collections import deque def solution(bridge_length, weight, truck_weights): # 최대 대수, 최대 하중, 트럭 무게 q = deque() res = 0 for i in range(bridge_length): q.append(0) i, s = 0, 0 # 순서, 다리에 올라간 무게, 개수 while True: if i not in range(len(truck_weights)): break res += 1 out = q.popleft() s -= out if s + truck_weights[i] 0: res += 1 out = q.popleft() s -= out q.a..

날짜 : 2023. 05. 29 사용 언어 : mysql 문제 코드 # 생산일자가 2022년 5월인 식품들의 식품 ID, 식품 이름, 총매출을 조회 # 총매출(o.amount * p.price)을 기준으로 내림차순 정렬해주시고 총매출이 같다면 식품 ID를 기준으로 오름차순 정렬 select p.product_id, p.product_name, sum(o.amount * p.price) as total_sales # 총량 계산 from food_product p join food_order o on p.product_id = o.product_id where o.produce_date like "2022-05-%" # 22년 5월 생산 group by product_id # product_id 별로 그룹화..