From 7a65b0276d2f3c5f2b7b94114ce7cb50231eba67 Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Sat, 18 May 2024 21:29:01 +0900 Subject: [PATCH] 2024-05-18 --- ...4\353\246\254 \352\262\214\354\236\204.py" | 49 +++++++++++++++++++ H0ngJu/README.md | 1 + 2 files changed, 50 insertions(+) create mode 100644 "H0ngJu/BFS/\353\261\200\352\263\274 \354\202\254\353\213\244\353\246\254 \352\262\214\354\236\204.py" diff --git "a/H0ngJu/BFS/\353\261\200\352\263\274 \354\202\254\353\213\244\353\246\254 \352\262\214\354\236\204.py" "b/H0ngJu/BFS/\353\261\200\352\263\274 \354\202\254\353\213\244\353\246\254 \352\262\214\354\236\204.py" new file mode 100644 index 00000000..3e159378 --- /dev/null +++ "b/H0ngJu/BFS/\353\261\200\352\263\274 \354\202\254\353\213\244\353\246\254 \352\262\214\354\236\204.py" @@ -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 \ No newline at end of file diff --git a/H0ngJu/README.md b/H0ngJu/README.md index 517e2252..2f4207eb 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -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 | ---