일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
- 백준
- 힙
- Dynamic Programming
- 알고리즘
- Algorithm
- Brute Force
- DVWA
- 그래프
- 탐욕법
- binary search
- 프로그래머스
- 코딩테스트
- graph
- BFS
- sort
- 문자열
- DP
- django
- DFS
- 동적계획법
- string
- Code Refactoring
- Greedy
- 정렬
- 완전탐색
- heap
- 카카오 기출
- programmers
- Queue
- 큐
- Today
- Total
목록Algorithm (65)
생각과 고민이 담긴 코드
문제 : https://programmers.co.kr/learn/courses/30/lessons/77484 코딩테스트 연습 - 로또의 최고 순위와 최저 순위 로또 6/45(이하 '로또'로 표기)는 1부터 45까지의 숫자 중 6개를 찍어서 맞히는 대표적인 복권입니다. 아래는 로또의 순위를 정하는 방식입니다. 1 순위 당첨 내용 1 6개 번호가 모두 일치 2 5개 번호 programmers.co.kr 풀이 def solution(lottos, win_nums): answer = [] rank = [6, 5, 4, 3, 2, 1] match = 0 unknown = 0 for lotto in lottos: if lotto == 0: unknown += 1 continue for win_num in win_..
문제 : https://www.acmicpc.net/problem/2667 2667번: 단지번호붙이기 과 같이 정사각형 모양의 지도가 있다. 1은 집이 있는 곳을, 0은 집이 없는 곳을 나타낸다. 철수는 이 지도를 가지고 연결된 집의 모임인 단지를 정의하고, 단지에 번호를 붙이려 한다. 여 www.acmicpc.net 풀이 import sys n = int(sys.stdin.readline()) city_map = [] result = [] global cnt cnt = 0 for _ in range(n): temp = list(sys.stdin.readline()) temp.pop() city_map.append(temp) def dfs(row, col): global cnt cnt += 1 city_..
문제 : https://www.acmicpc.net/problem/15686 15686번: 치킨 배달 크기가 N×N인 도시가 있다. 도시는 1×1크기의 칸으로 나누어져 있다. 도시의 각 칸은 빈 칸, 치킨집, 집 중 하나이다. 도시의 칸은 (r, c)와 같은 형태로 나타내고, r행 c열 또는 위에서부터 r번째 칸 www.acmicpc.net 풀이 import sys from itertools import combinations def calculate(stores): result = 0 for k in home: result += min([abs(l[0] - k[0]) + abs(l[1] - k[1]) for l in stores]) return result n, m = map(int, sys.stdin..
문제 : https://programmers.co.kr/learn/courses/30/lessons/12979 코딩테스트 연습 - 기지국 설치 N개의 아파트가 일렬로 쭉 늘어서 있습니다. 이 중에서 일부 아파트 옥상에는 4g 기지국이 설치되어 있습니다. 기술이 발전해 5g 수요가 높아져 4g 기지국을 5g 기지국으로 바꾸려 합니다. 그런데 5 programmers.co.kr 풀이 from math import ceil def solution(n, stations, w): answer = 0 for i in range(len(stations)+1): if i == 0: # 첫 아파트부터 첫번째 station까지의 구간 answer += ceil((stations[i]-w-1) / (2*w+1)) elif ..
문제 : https://programmers.co.kr/learn/courses/30/lessons/49993 코딩테스트 연습 - 스킬트리 programmers.co.kr 풀이 def solution(skill, skill_trees): answer = 0 n = len(skill) for i in skill_trees: check = [0]*n error = False for j in i: if j in skill: idx = skill.index(j) if idx != 0 and check[idx-1] == 0: error = True break else: check[idx] = 1 if not error: answer += 1 return answer 쉬운 문제였다. 생각해보면 skill에 있는 문..
문제 : https://www.acmicpc.net/problem/14502 14502번: 연구소 인체에 치명적인 바이러스를 연구하던 연구소에서 바이러스가 유출되었다. 다행히 바이러스는 아직 퍼지지 않았고, 바이러스의 확산을 막기 위해서 연구소에 벽을 세우려고 한다. 연구소는 크 www.acmicpc.net 풀이 import sys from itertools import combinations from copy import deepcopy def virus(row, col): if row > 0 and map_lab[row - 1][col] == 0: map_lab[row - 1][col] = 2 virus(row - 1, col) if row < N - 1 and map_lab[row + 1][col]..
문제 : https://www.acmicpc.net/problem/11725 11725번: 트리의 부모 찾기 루트 없는 트리가 주어진다. 이때, 트리의 루트를 1이라고 정했을 때, 각 노드의 부모를 구하는 프로그램을 작성하시오. www.acmicpc.net 풀이 import sys from collections import defaultdict from collections import deque n = int(sys.stdin.readline()) tree = defaultdict(list) for _ in range(n - 1): edge = sys.stdin.readline().split() tree[edge[0]].append(edge[1]) tree[edge[1]].append(edge[0]) ..
문제 : https://www.acmicpc.net/problem/1487 1487번: 물건 팔기 첫째 줄에 최대 이익을 만들어주는 가격을 출력한다. 이익이 최대인 가격이 여러개라면, 가장 낮은 가격을 출력한다. 또, 어떤 가격으로 팔아도 이익을 남길 수 없다면 0을 출력한다. www.acmicpc.net 풀이 import sys n = int(sys.stdin.readline()) cost = [] for _ in range(n): # [가격, 배달비] 형태로 생성. temp = list(map(int, sys.stdin.readline().split())) cost.append([temp[0], temp[1]]) cost.sort(key=lambda x: (x[0], x[1])) # 가격, 배달비 순..