[프로그래머스] DFS/BFS - 게임 맵 최단거리
아직 BFS가 낯설어서! 다른 분 코드 참고 from collections import deque def solution(maps): # 방향 설정 : 앞,아래,뒤,위 dx = [-1,0,1,0] dy = [0,1,0,-1] result = 0 n = len(maps) # 행 개수 m = len(maps[0]) # 각 열마다 몇 개 있는 지, ck = [[0]*m for _ in range(n)] # n*m 2차원 배열 생성 dis = [[0]*m for _ in range(n)] # n*m 2차원 배열 생성 queue = deque() # 큐 생성 ck[0][0] = 1 #방문처리 dis[0][0] = 1 #방문처리 queue.append((0,0)) #큐에 삽입 while queue: now = qu..
2024. 3. 22.
[프로그래머스] 완전탐색 - 카펫
나의 답 def check(brown, yellow,x,y): b = x*y-((x-2)*(y-2)) y = (x-2)*(y-2) if brown == b and yellow == y: return 1 else: return 0 def solution(brown, yellow): cnt = brown+yellow arr = [] for i in range(3,cnt+1): # 약수 구하기 if cnt%i==0: arr.append(i) for value in arr: # 약수 조합 활용 x = value y = int(cnt/value) if check(brown, yellow,x,y): # 가로, 세로 값에 따라서 brown, yellow 충족 확인 return [x,y] if x>y else [y, ..
2024. 3. 18.