Skip to content

Commit

Permalink
2024-05-18
Browse files Browse the repository at this point in the history
  • Loading branch information
H0ngJu committed May 18, 2024
1 parent 45ac9fd commit 7a65b02
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import sys
from collections import deque

def input(): return sys.stdin.readline().rstrip()

N, M = map(int, input().split())
ladder = [list(map(int, input().split())) for _ in range(N)]
snake = [list(map(int, input().split())) for _ in range(M)]
game = [i for i in range(1,101)]
visited = [0 for _ in range(100)]
q = deque()

q.append((1,0))
visited[0] = 1

while q:
cur, dice = q.popleft()
if cur == 100:
print(dice)
break
for i in range(1, 7):
check = 0

if cur + i > 100: continue

# ์‚ฌ๋‹ค๋ฆฌ ๊ฐˆ ์ˆ˜ ์žˆ๋Š”์ง€ ๊ฒ€์‚ฌ
for l, n in ladder:
if cur + i == l:
if visited[n-1] == 0:
q.append((n, dice+1))
visited[n-1] = 1
check = 1
break

if check: continue
# ๋ฑ€ ์žˆ๋Š”์ง€ ๊ฒ€์‚ฌ
for s, n in snake:
if cur + i == s:
if visited[n-1] == 0:
q.append((n, dice+1))
visited[n-1] = 1
check = 1
break

if check: continue
# ๊ทธ ์™ธ
if visited[cur + i-1] == 0:
q.append((cur + i, dice + 1))
visited[cur + i-1] = 1
1 change: 1 addition & 0 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
| 13์ฐจ์‹œ | 2024.05.06 | ์™„์ „ํƒ์ƒ‰ | [๋ฆฌ๋ชจ์ปจ](https://www.acmicpc.net/problem/1107) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/181 |
| 14์ฐจ์‹œ | 2024.05.09 | DFS | [์น˜ํ‚จ๋ฐฐ๋‹ฌ](https://www.acmicpc.net/problem/15686) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/183 |
| 15์ฐจ์‹œ | 2024.05.14 | ๊ทธ๋ฆฌ๋”” | [A์™€ B](https://www.acmicpc.net/problem/12904) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/188 |
| 16์ฐจ์‹œ | 2024.05.14 | BFS | [๋ฑ€๊ณผ ์‚ฌ๋‹ค๋ฆฌ ๊ฒŒ์ž„](https://www.acmicpc.net/problem/16928) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/191 |

---

0 comments on commit 7a65b02

Please sign in to comment.