Skip to content

Commit

Permalink
Merge pull request #233 from AlgoLeadMe/24-H0ngJu
Browse files Browse the repository at this point in the history
24-H0ngJu
  • Loading branch information
H0ngJu authored Aug 19, 2024
2 parents a3f273b + 03a308d commit e6f1e10
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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)

64 changes: 64 additions & 0 deletions H0ngJu/BFS/์•„๊ธฐ์ƒ์–ด.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import sys
from collections import deque

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

N = int(input())
space = [list(map(int, input().split())) for _ in range(N)]

dir = [(0,1), (0,-1), (1,0), (-1,0)]
x = 0
y = 0

for i in range(N):
for j in range(N):
if space[i][j] == 9:
x, y = i, j
space[x][y] = 0

def check(a, b):
if 0<=a<N and 0<=b<N:
return True
return False

baby = 2

time = 0
fish = 0

while True:
q = deque([(x, y, 0)])
visited = [[False] * N for _ in range(N)]
visited[x][y] = True
min_dis = float('inf')
tmp = []

while q:
cx, cy, dis = q.popleft()

if 0 < space[cx][cy] < baby:
if dis < min_dis:
min_dis = dis
tmp = [(cx, cy)]
elif dis == min_dis:
tmp.append((cx, cy))

for dx, dy in dir:
nx, ny = cx + dx, cy + dy
if check(nx, ny) and not visited[nx][ny] and space[nx][ny] <= baby:
visited[nx][ny] = True
q.append((nx, ny, dis + 1))

if not tmp:
break

tx, ty = min(tmp)
space[tx][ty] = 0
time += min_dis
fish += 1
if fish == baby:
baby += 1
fish = 0
x, y = tx, ty

print(time)
3 changes: 2 additions & 1 deletion H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.17 | BFS | [์•„๊ธฐ์ƒ์–ด](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 |

---

0 comments on commit e6f1e10

Please sign in to comment.