Skip to content

'찬민구현숙제' #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions cmkim/BaekJoon/백준_17090.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import sys
sys.setrecursionlimit(10**9)

dir = {'U': (-1, 0), 'R': (0, 1), 'D': (1, 0), 'L': (0, -1)}

def dfs(x, y):
if 0 > x or x >= n or 0 > y or y >= m: #탈출
return True

if arr[x][y] == 'true':# 탈출 확정된 곳
return True
elif arr[x][y] == 'false':# 탈출 불가능 확정된 곳
return False

if visited[x][y]:
return False
else:
visited[x][y] = 1
dx, dy = dir[arr[x][y]]
nx = x + dx
ny = y + dy

result = dfs(nx, ny)
arr[x][y] = 'true' if result else 'false'
return result


n, m = map(int, input().split())
arr = []
visited = [[0]*m for _ in range(n)]
for i in range(n):
arr.append(list(input()))

# for i in range(n):
# print(arr[i])

# ax, ay = dir[arr[0][0]]
# print('ax, ay = ', ax, ay)

count = 0
for x in range(n):
for y in range(m):
if dfs(x, y):
count += 1

print(count)

2 changes: 1 addition & 1 deletion cmkim/BaekJoon/백준_2533.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
input = sys.stdin.readline

sys.setrecursionlimit(10**9)
n = int(input())
tree = [[] for _ in range(n+1)]
Expand Down Expand Up @@ -28,5 +27,6 @@ def bfs(root):

bfs(1)


print(min(dp[1][0], dp[1][1]))

29 changes: 29 additions & 0 deletions cmkim/BaekJoon/백준_2931.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from collections import deque

dx = [-1, 1, 0, 0] # 상하좌우
dy = [0, 0, -1, 1]

way = {'M': [0, 1, 2, 3], '|': [0, 1], '-': [2, 3], '+': [0, 1, 2, 3], '1': [1, 3], '2': [0, 3], '3': [0, 2], '4': [1, 2]}

def bfs(x, y):
dir = way[arr[x][y]]
for i in dir:
nx = x + dx[i]
ny = y + dy[i]



r, c = map(int, input().split())
arr = []

for i in range(r):
arr.append(list(input()))

for i in range(r):
for j in range(c):
if arr[i][j] == 'M':
x, y = i, j
# for i in range(r):
# print(arr[i])

bfs(x, y)
39 changes: 39 additions & 0 deletions cmkim/BaekJoon/백준_5547.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys
from collections import deque
input = sys.stdin.readline

odd = [(-1, 1), (0, 1), (1, 1), (1, 0), (0, -1), (-1, 0)] #행, 렬 기준으로함 정각부터 정시계방향으로 순환
even = [(-1, 0), (0, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def bfs(x, y):
q = deque([(x, y)])
count = 0
while q:
x, y = q.popleft()
visited[x][y] = 1
dir = even if x%2 == 0 else odd
for i in range(6):
dx, dy = dir[i][0], dir[i][1]
nx, ny = x + dx, y + dy

if 0 <= nx < h+2 and 0 <= ny < w+2:
if arr[nx][ny] == 1:
count += 1
elif arr[nx][ny] == 0 and not visited[nx][ny]:
visited[nx][ny] = 1
q.append((nx, ny))
return count



w, h = map(int, input().split()) # 열, 행 순서로 입력
arr = [[0] * (w+2)]
visited = [[0] * (w+2) for _ in range(h+2)]
for i in range(h):
arr.append([0]+list(map(int, input().split())) + [0])
arr.append([0 for _ in range(w+2)])

# for i in range(h+2):
# print(arr[i])

print(bfs(0, 0))