Skip to content

Commit b02fc28

Browse files
committed
'찬민구현숙제'
1 parent 5d5ca3c commit b02fc28

File tree

6 files changed

+162
-1
lines changed

6 files changed

+162
-1
lines changed

cmkim/BaekJoon/백준 1260.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
def DFS(v, visited):
33

44
visited[v] = 1
5-
print(v, end = ' ') # end= ' ' -> 다음 출력값 사이의 간격 조정(줄바꿈도 생략가능)
5+
print(v, end=' ') # end= ' ' -> 다음 출력값 사이의 간격 조정(줄바꿈도 생략가능)
66

77
for i in range(1, n+1):
88

cmkim/BaekJoon/백준_1062.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
n, k = map(int, input().split())
2+
3+
arr = []
4+
teach = []
5+
for i in range(n):
6+
arr.append(input())
7+
# for i in range(n):
8+
# print(arr[i])
9+
for i in range(n):
10+
teach.append(arr[i][4:-4])
11+
# for i in range(n):
12+
# print(teach[i])
13+
for i in range(n):
14+
teach[i] = set(teach[i])
15+
# for i in range(n):
16+
# print(teach[i])

cmkim/BaekJoon/백준_17090.py

Lines changed: 47 additions & 0 deletions
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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
input = sys.stdin.readline
3+
sys.setrecursionlimit(10**9)
4+
n = int(input())
5+
tree = [[] for _ in range(n+1)]
6+
dp = [[0, 0] for _ in range(n + 1)]
7+
visited = [0 for _ in range(n + 1)]
8+
9+
for i in range(n-1):
10+
a, b = map(int, input().split())
11+
12+
tree[a].append(b)
13+
tree[b].append(a)
14+
15+
#print(tree)
16+
17+
def bfs(root):
18+
visited[root] = True
19+
dp[root][0] = 0
20+
dp[root][1] = 1
21+
22+
for i in tree[root]:
23+
if not visited[i]:
24+
bfs(i)
25+
dp[root][0] += dp[i][1]
26+
dp[root][1] += min(dp[i][0], dp[i][1])
27+
28+
bfs(1)
29+
30+
print(min(dp[1][0], dp[1][1]))

cmkim/BaekJoon/백준_2931.py

Lines changed: 29 additions & 0 deletions
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

Lines changed: 39 additions & 0 deletions
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)