Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 항해99솔직후기 #항해99 #부트캠프추천
- 스파르타코딩클럽 #크롤링 #스크래핑
- 부트스트랩 #Bootstrap #웹개발첫걸음 #스파르타코딩클럽
- 스파르타코딩클럽 #코딩 #jQuery #Ajax
- #내일배움단 #코딩프로젝트 #국비지원 #내일배움카드 #스파르타코딩클럽
Archives
- Today
- Total
이모저모
BFS(넓이 우선 탐색) 익히기 _ 송아지찾기문제 본문
김태원 선생님의 강의를 들으면서!
아무래도 나같이 찬찬한 이해의 시간이 필요한 사람에겐 필기/그림으로 먼저 정리하고 코드로 쓰는 게 좋은 것 같다!!
+ 어제 종이질감필름 사길 너무 잘했다..ㅎㅎ
import collections
def findCow(start:int, destination: int, max_position: int):
positions_que = collections.deque()
positions_que.append(start)
distance = [0] * (max_position + 1)
distance[start] = 0
checked = [0] *(max_position + 1)
while positions_que:
now = positions_que.popleft()
if now == destination:
break
for next in (now-1, now+1, now+5):
if 0 < next <= max_position:
if checked[next] == 0:
positions_que.append(next)
checked[next] = 1
distance[next] = distance[now] + 1
return distance[destination]
# 예제 확인 print(findCow(5, 14, 10000))
'coding > 알고리즘,자료구조' 카테고리의 다른 글
leetcode - 섬의 개수 (DFS로 풀기) (0) | 2022.01.22 |
---|---|
가중치가 있는 인접행렬 출력해보기 (0) | 2022.01.22 |
leetcode - combinations (조합) _ DFS(깊이 우선 탐색) (0) | 2022.01.22 |
leetcode - permutations (순열 - 중복 피하기) (0) | 2022.01.21 |
leetcode - 전화번호 조합 feat.DFS (0) | 2022.01.21 |
Comments