๋ฌธ์
https://www.acmicpc.net/problem/9205
ํ์ด
# ๋ฐฑ์ค 9205๋ฒ ๋ฌธ์ - ๋งฅ์ฃผ ๋ง์๋ฉด์ ๊ฑธ์ด๊ฐ๊ธฐ
import sys
from collections import deque
input = sys.stdin.readline
def bfs():
q = deque()
q.append([home[0], home[1]])
while q:
x, y = q.popleft()
if abs(x-festival[0]) + abs(y-festival[1]) <= 1000: # ๊ฑฐ๋ฆฌ๊ฐ 1000์ด๋ด์ผ ๊ฒฝ์ฐ
print('happy')
return
for i in range(n):
if not visited[i]:
new_x, new_y = conv[i]
if abs(x-new_x) + abs(y-new_y) <= 1000:
q.append([new_x, new_y])
visited[i] = 1
print('sad')
return
t = int(input())
for _ in range(t):
n = int(input())
home = [int(x) for x in input().split()]
conv = []
for _ in range(n):
conv.append(list(map(int, input().split())))
festival = [int(x) for x in input().split()]
visited = [0 for i in range(n+1)]
bfs()
dxdy ํ์ด๋ก๋ง ํ๋ค๊ฐ ์๊ฐ์ ๋ฐ๊ฟ์ ํด๋ณด๋๋ก ๋ ธ๋ ฅํด์ผ๊ฒ ๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] 10844๋ฒ_์ฌ์ด ๊ณ๋จ ์ (0) | 2022.11.26 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] 1325๋ฒ_ํจ์จ์ ์ธ ํดํน (0) | 2022.11.26 |
๐ฉ [๋ฐฑ์ค] [Python] [DP] 2156๋ฒ_ํฌ๋์ฃผ ์์ (0) | 2022.11.26 |
๐ฉ [๋ฐฑ์ค] [Python] [๊ตฌํ] 15686๋ฒ_์นํจ ๋ฐฐ๋ฌ (0) | 2022.11.22 |
๐ฉ [๋ฐฑ์ค] [Python] 1987๋ฒ_์ํ๋ฒณ (1) | 2022.11.21 |