Skip to content

Commit 2482c09

Browse files
authored
'찬민구현숙제' (#106)
* '찬민구현숙제' * Delete 백준 1260.py * Delete 백준_1062.py
1 parent 3b57a52 commit 2482c09

File tree

4 files changed

+116
-1
lines changed

4 files changed

+116
-1
lines changed

‎cmkim/BaekJoon/백준_17090.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import sys
2+
sys.setrecursionlimit(10**9)
3+
4+
dir = {'U': (-1, 0), 'R': (0, 1), 'D': (1, 0), 'L': (0, -1)}
5+
6+
def dfs(x, y):
7+
if 0 > x or x >= n or 0 > y or y >= m: #탈출
8+
return True
9+
10+
if arr[x][y] == 'true':# 탈출 확정된 곳
11+
return True
12+
elif arr[x][y] == 'false':# 탈출 불가능 확정된 곳
13+
return False
14+
15+
if visited[x][y]:
16+
return False
17+
else:
18+
visited[x][y] = 1
19+
dx, dy = dir[arr[x][y]]
20+
nx = x + dx
21+
ny = y + dy
22+
23+
result = dfs(nx, ny)
24+
arr[x][y] = 'true' if result else 'false'
25+
return result
26+
27+
28+
n, m = map(int, input().split())
29+
arr = []
30+
visited = [[0]*m for _ in range(n)]
31+
for i in range(n):
32+
arr.append(list(input()))
33+
34+
# for i in range(n):
35+
# print(arr[i])
36+
37+
# ax, ay = dir[arr[0][0]]
38+
# print('ax, ay = ', ax, ay)
39+
40+
count = 0
41+
for x in range(n):
42+
for y in range(m):
43+
if dfs(x, y):
44+
count += 1
45+
46+
print(count)
47+

‎cmkim/BaekJoon/백준_2533.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import sys
22
input = sys.stdin.readline
3-
43
sys.setrecursionlimit(10**9)
54
n = int(input())
65
tree = [[] for _ in range(n+1)]
@@ -28,5 +27,6 @@ def bfs(root):
2827

2928
bfs(1)
3029

30+
3131
print(min(dp[1][0], dp[1][1]))
3232

‎cmkim/BaekJoon/백준_2931.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from collections import deque
2+
3+
dx = [-1, 1, 0, 0] # 상하좌우
4+
dy = [0, 0, -1, 1]
5+
6+
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]}
7+
8+
def bfs(x, y):
9+
dir = way[arr[x][y]]
10+
for i in dir:
11+
nx = x + dx[i]
12+
ny = y + dy[i]
13+
14+
15+
16+
r, c = map(int, input().split())
17+
arr = []
18+
19+
for i in range(r):
20+
arr.append(list(input()))
21+
22+
for i in range(r):
23+
for j in range(c):
24+
if arr[i][j] == 'M':
25+
x, y = i, j
26+
# for i in range(r):
27+
# print(arr[i])
28+
29+
bfs(x, y)

‎cmkim/BaekJoon/백준_5547.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import sys
2+
from collections import deque
3+
input = sys.stdin.readline
4+
5+
odd = [(-1, 1), (0, 1), (1, 1), (1, 0), (0, -1), (-1, 0)] #행, 렬 기준으로함 정각부터 정시계방향으로 순환
6+
even = [(-1, 0), (0, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
7+
8+
def bfs(x, y):
9+
q = deque([(x, y)])
10+
count = 0
11+
while q:
12+
x, y = q.popleft()
13+
visited[x][y] = 1
14+
dir = even if x%2 == 0 else odd
15+
for i in range(6):
16+
dx, dy = dir[i][0], dir[i][1]
17+
nx, ny = x + dx, y + dy
18+
19+
if 0 <= nx < h+2 and 0 <= ny < w+2:
20+
if arr[nx][ny] == 1:
21+
count += 1
22+
elif arr[nx][ny] == 0 and not visited[nx][ny]:
23+
visited[nx][ny] = 1
24+
q.append((nx, ny))
25+
return count
26+
27+
28+
29+
w, h = map(int, input().split()) # 열, 행 순서로 입력
30+
arr = [[0] * (w+2)]
31+
visited = [[0] * (w+2) for _ in range(h+2)]
32+
for i in range(h):
33+
arr.append([0]+list(map(int, input().split())) + [0])
34+
arr.append([0 for _ in range(w+2)])
35+
36+
# for i in range(h+2):
37+
# print(arr[i])
38+
39+
print(bfs(0, 0))

0 commit comments

Comments
 (0)