diff --git a/seongwon030/README.md b/seongwon030/README.md index 0a76bfa..cef8891 100644 --- a/seongwon030/README.md +++ b/seongwon030/README.md @@ -1,9 +1,10 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -| :---: | :--------: | :------: | :-----------------------------------------------: | :------------------------------------------------------: | -| 1차시 | 2024.03.11 | 스택 | [쇠막대기](https://www.acmicpc.net/problem/10799) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/2) | -| 2차시 | 2024.03.16 | BFS | [토마토](https://www.acmicpc.net/problem/7576) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/7) | -| 3차시 | 2024.03.19 | BFS | [토마토](https://www.acmicpc.net/problem/7569) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/9) | +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | +| :---: | :--------: | :------: | :------------------------------------------------: | :------------------------------------------------------: | +| 1차시 | 2024.03.11 | 스택 | [쇠막대기](https://www.acmicpc.net/problem/10799) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/2) | +| 2차시 | 2024.03.16 | BFS | [토마토](https://www.acmicpc.net/problem/7576) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/7) | +| 3차시 | 2024.03.19 | BFS | [토마토](https://www.acmicpc.net/problem/7569) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/9) | +| 4차시 | 2024.03.25 | BFS | [숨바꼭질3](https://www.acmicpc.net/problem/13549) | [#17](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/9) | --- diff --git "a/seongwon030/bfs/\354\210\250\353\260\224\352\274\255\354\247\2103.py" "b/seongwon030/bfs/\354\210\250\353\260\224\352\274\255\354\247\2103.py" new file mode 100644 index 0000000..8676b7f --- /dev/null +++ "b/seongwon030/bfs/\354\210\250\353\260\224\352\274\255\354\247\2103.py" @@ -0,0 +1,28 @@ +from collections import deque +import sys + +input = sys.stdin.readline + +result = 0 +MAX = 10**5 # 움직일 수 있는 최대좌표 +dist = [-1] * (MAX + 1) # 해당 위치에 도착했을 때 시간 +n, k = map(int,input().split()) + +q = deque() +q.append(n) +dist[n] = 0 # 시작위치를 체크하기 위해 0으로 설정 +while q: + x = q.popleft() + if x==k: # x변수인 수빈의 위치가 동생이 있는 k와 같을 때 멈춤 + result = dist[x] + break + # nx = 4,6,10 (현재 위치 5일 때 이동할 수 있는 방향) + for nx in (x*2, x-1, x+1): + # 범위내에 있고 아직 방문안했다면 + if 0<=nx<=MAX and dist[nx] == -1: + if nx == x*2: # 곱하기2를 한 좌표부터 체크 + dist[nx] = dist[x] + else: + dist[nx] = dist[x] + 1 + q.append(nx) +print(result) \ No newline at end of file