diff --git "a/H0ngJu/BFS/\353\247\245\354\243\274 \353\247\210\354\213\234\353\251\264\354\204\234 \352\261\270\354\226\264\352\260\200\352\270\260.py" "b/H0ngJu/BFS/\353\247\245\354\243\274 \353\247\210\354\213\234\353\251\264\354\204\234 \352\261\270\354\226\264\352\260\200\352\270\260.py" new file mode 100644 index 00000000..d2ab3dc4 --- /dev/null +++ "b/H0ngJu/BFS/\353\247\245\354\243\274 \353\247\210\354\213\234\353\251\264\354\204\234 \352\261\270\354\226\264\352\260\200\352\270\260.py" @@ -0,0 +1,45 @@ +import sys +from collections import deque + +def input() : return sys.stdin.readline().rstrip() + +t = int(input()) +dx = [-1, 1, 0, 0] +dy = [0, 0, -1, 1] + + +for i in range(t): + n = int(input()) + hx, hy = map(int, input().split()) + store = [list(map(int, input().split())) for _ in range(n)] + fx, fy = map(int, input().split()) + + x, y = hx, hy + result = "sad" + + q = deque([(x, y, 20)]) + visited = set([x, y]) + + while q: + x, y, beer = q.popleft() + + if abs(x-fx) + abs(y-fy) <= 50*beer: # 축제까지 갈 수 있는지 + result = "happy" + break + + for sx, sy in store: # 편의점 들릴 수 있는지 + if abs(x-sx) + abs(y-sy) <= 50 * beer and (sx, sy) not in visited: + visited.add((sx, sy)) + q.append((sx, sy, 20)) + + if beer > 0: # beer 먹고 가기 + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + + if (nx, ny) not in visited: + visited.add((nx, ny)) + q.append((nx, ny, beer - 1)) + + print(result) + \ No newline at end of file diff --git a/H0ngJu/README.md b/H0ngJu/README.md index c76b9d05..0bd14495 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -22,7 +22,8 @@ | 18차시 | 2024.05.26 | DFS | [계란으로 계란치기](https://www.acmicpc.net/problem/16987) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/199 | | 19차시 | 2024.05.31 | DP | [합분해](https://www.acmicpc.net/problem/2225) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/202 | | 20차시 | 2024.06.03 | 백트래킹 | [스타트와 링크](https://www.acmicpc.net/problem/14889) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/206 | +| 21차시 | 2024.06.07 | 그리디 | [행복 유치원](https://www.acmicpc.net/problem/13164) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/208 | -| 21차시 | 2024.06.07 | 그리디 | [행복 유치원](https://www.acmicpc.net/problem/13164) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/208 | +| 24차시 | 2024.08.12 | BFS | [맥주 마시면서 걸어가기](https://www.acmicpc.net/problem/9205) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/229 | ---