분류 전체보기(89)
-
[BOJ]14395 4연산 Python 풀이
from collections import deque s, t = map(int, input().split()) MAX = 10e9 def BFS(): visited = set() q = deque() q.append((s, '')) operator = ['*', '+', '/'] result = -1 if s == t: return 0 while q: node, op = q.popleft() if node == t: result = op break for o in operator: calc = eval(str(node) + o + str(node)) if 0
2023.04.10 -
[boj] 2667 단지번호붙이기 Python
n = int(input()) graph = [list(map(int, input())) for _ in range(n)] def DFS(x, y): graph[x][y] = 0 res = 0 dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] for i in range(4): xx = dx[i] + x yy = dy[i] + y if 0
2023.04.08 -
[BOJ] 20169 세 번 이내에 사과를 먹자 Python
import pprint graph = [] visited = [[False for _ in range(5)] for __ in range(5)] flag = False for i in range(5): graph.append(list(map(int, input().split()))) n, m = map(int, input().split()) def BFS(x, y, apple, depth = 0): global flag visited[x][y] = True dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] if (depth = 2): flag = True return if (depth >= 3 and apple < 2): return for i in range(4): xx = dx[i..
2023.04.08 -
BOJ 1012 유기농 배추 Python
일반적인 DFS 문제이며, 재귀를 이용한 DFS 구현으로 풀었다. 맨 처음에 Recursion error가 발생했는데, 백준에서 재귀를 1000 이하로만 설정하지만, 2500번의 재귀가 발생할 수 있으므로 설정 값을 바꿔줌으로서 해결했다. 아래는 코드이다. import sys sys.setrecursionlimit(10**6) def dfs(x, y, graph): if x = len(graph[0]): return 0 if graph[x][y] == 1: graph[x][y] = 0 dfs(x + 1, y, graph) dfs(x, y + 1, graph) dfs(x - 1, y, graph) dfs(x, y - 1, graph) return 1 return 0 def solve(): vert, hor..
2023.04.06 -
2023.04.01
방법을 약간 수정하기로 했다. Greedy의 실버 수준 문제까지는 단순 정렬만 이용해도 됐지만 그 이상 올라가려면 보통 그래프 등을 사용하는 모습이 많이 보였다. 그래서 책을 1회독을 끝낸 뒤 다시 한번 더 높은 수준을 향해 가기로 했다. 어제까진 하루 약 2~3문제 정도의 문제를 풀이하였고, 어제 회고록이 올라오지 않은 이유는 공모전 시나리오 제출 마감이었기 때문이다. 근무있는 월요일은 수학 풀면 될것이고.. 뭐 이정도만 짜두고 나머지는 그 때 가서 정하면 될 일이다. 갓생살기 시작
2023.04.01 -
[BOJ] 9237 Python | Silver V
plant = int(input()) lst = list(map(sum, zip(sorted(list(map(int, input().split())), reverse=True), [i for i in range (1, plant + 1)]))) print(max(lst) + 1) 정렬하고 뒤집고 합치고 1 더하면 끝.. ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
2023.03.31