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 |
Tags
- 혼공머신
- Brightics Studio
- Brigthics를 이용한 분석
- Brightics를 이용한 분석
- 데이터분석
- 브라이틱스 서포터즈
- 혼공머신러닝딥러닝
- 팀 분석
- 삼성SDS
- 직원 이직여부
- 포스코 청년
- 혼공학습단
- 직원 이직률
- 모델링
- 삼성 SDS
- 혼공
- 추천시스템
- 삼성SDS Brigthics
- 포스코 아카데미
- 데이터 분석
- 개인 의료비 예측
- Brigthics Studio
- 삼성 SDS Brigthics
- Brigthics
- 캐글
- 삼성SDS Brightics
- 영상제작기
- 브라이틱스
- 노코드AI
- Brightics
Archives
- Today
- Total
데이터사이언스 기록기📚
[백준/Python] 14248번(BFS)_점프 점프 본문
📌문제 유형
그래프이론, 그래프 탐색, DFS, BFS (실버2)
📌문제
14248번: 점프 점프
첫 번째 줄에는 돌다리의 돌 개수 n이 주어진다.(1≤n≤100,000) 돌의 번호는 왼쪽부터 1번에서 n번이다. 다음 줄에는 그 위치에서 점프할 수 있는 거리 Ai가 주어진다.(1≤Ai≤100,000) 다음 줄에는 출
www.acmicpc.net
📌나의 문제풀이
- 틀림
from collections import deque
n = int(input())
num_list = list(map(int,input().split()))
start = int(input())
graph = [[] for _ in range(n+1)]
for i in range(len(num_list)):
graph[i+1].append((i+1) - num_list[i] if (i+1) - num_list[i] > 0 else 1)
graph[i+1].append((i+1) + num_list[i] if (i+1) + num_list[i] < n+1 else n)
visited = [False] * (n+1)
q = deque()
for num in graph[start]:
q.append((start, num))
# 오류
while q:
now, next = q.popleft()
if visited[now] == True or now == next:
continue
visited[now] = True
for num in graph[next]:
if not visited[next]:
q.append((next, num))
visited[now] = True
ans = 0
for v in visited:
if v == True:
ans += 1
print(ans)
📌 다른사람의 문제풀이
백준 알고리즘 14248번 점프 점프(python)
기본적인 BFS 문제이다. from collections import deque def bfs(node): q = deque() q.append(node) check[node] = 1 while q: node = q.popleft() for d in [-graph[node], graph[node]]: t = node+d if (0
jinho-study.tistory.com
from collections import deque
def bfs(node):
q = deque()
q.append(node)
check[node] = 1
while q:
node = q.popleft()
for d in [-graph[node], graph[node]]:
t = node+d
if (0 <= t < n) and check[t] == 0:
q.append(t)
check[t] = 1
n = int(input())
graph = list(map(int, input().split()))
s = int(input())-1
check = [0]*(n)
bfs(s)
print(check.count(1))
📌 리뷰
- 방문 가능한 거리가 for문으로 움직여야 함
- BFS 코드 익히기 (while q전에 첫 노드 visited = True, 이후 q.append() 시 visited = True)
728x90
'Coding Test > 백준(Python)' 카테고리의 다른 글
[백준/Python] 2178번(BFS)_미로 탐색 (0) | 2023.04.20 |
---|---|
[백준/Python] 20115번(그리디)_에너지 드링크 (0) | 2023.04.20 |
[백준/Python] 13699번(DP)_점화식 (0) | 2023.04.19 |
[백준/Python] 2210번(DFS, 브루트포스)_숫자판 점프 (0) | 2023.04.19 |
[백준/Python] 1018번(브루트포스 알고리즘)_체스판 다시 칠하기 (0) | 2023.04.18 |
Comments