From b02fc28e959f69b09de7ce15ce1f776c6298c06d Mon Sep 17 00:00:00 2001 From: bsyzch Date: Mon, 6 Sep 2021 20:45:10 +0900 Subject: [PATCH 1/3] =?UTF-8?q?'=EC=B0=AC=EB=AF=BC=EA=B5=AC=ED=98=84?= =?UTF-8?q?=EC=88=99=EC=A0=9C'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 1260.py" | 2 +- .../\353\260\261\354\244\200_1062.py" | 16 +++++++ .../\353\260\261\354\244\200_17090.py" | 47 +++++++++++++++++++ .../\353\260\261\354\244\200_2533.py" | 30 ++++++++++++ .../\353\260\261\354\244\200_2931.py" | 29 ++++++++++++ .../\353\260\261\354\244\200_5547.py" | 39 +++++++++++++++ 6 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 "cmkim/BaekJoon/\353\260\261\354\244\200_1062.py" create mode 100644 "cmkim/BaekJoon/\353\260\261\354\244\200_17090.py" create mode 100644 "cmkim/BaekJoon/\353\260\261\354\244\200_2533.py" create mode 100644 "cmkim/BaekJoon/\353\260\261\354\244\200_2931.py" create mode 100644 "cmkim/BaekJoon/\353\260\261\354\244\200_5547.py" diff --git "a/cmkim/BaekJoon/\353\260\261\354\244\200 1260.py" "b/cmkim/BaekJoon/\353\260\261\354\244\200 1260.py" index 1e3b9d4..8df7e8a 100644 --- "a/cmkim/BaekJoon/\353\260\261\354\244\200 1260.py" +++ "b/cmkim/BaekJoon/\353\260\261\354\244\200 1260.py" @@ -2,7 +2,7 @@ def DFS(v, visited): visited[v] = 1 - print(v, end = ' ') # end= ' ' -> 다음 출력값 사이의 간격 조정(줄바꿈도 생략가능) + print(v, end=' ') # end= ' ' -> 다음 출력값 사이의 간격 조정(줄바꿈도 생략가능) for i in range(1, n+1): diff --git "a/cmkim/BaekJoon/\353\260\261\354\244\200_1062.py" "b/cmkim/BaekJoon/\353\260\261\354\244\200_1062.py" new file mode 100644 index 0000000..b2a7d69 --- /dev/null +++ "b/cmkim/BaekJoon/\353\260\261\354\244\200_1062.py" @@ -0,0 +1,16 @@ +n, k = map(int, input().split()) + +arr = [] +teach = [] +for i in range(n): + arr.append(input()) +# for i in range(n): +# print(arr[i]) +for i in range(n): + teach.append(arr[i][4:-4]) +# for i in range(n): +# print(teach[i]) +for i in range(n): + teach[i] = set(teach[i]) +# for i in range(n): +# print(teach[i]) \ No newline at end of file diff --git "a/cmkim/BaekJoon/\353\260\261\354\244\200_17090.py" "b/cmkim/BaekJoon/\353\260\261\354\244\200_17090.py" new file mode 100644 index 0000000..13b5083 --- /dev/null +++ "b/cmkim/BaekJoon/\353\260\261\354\244\200_17090.py" @@ -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) + diff --git "a/cmkim/BaekJoon/\353\260\261\354\244\200_2533.py" "b/cmkim/BaekJoon/\353\260\261\354\244\200_2533.py" new file mode 100644 index 0000000..48b95d6 --- /dev/null +++ "b/cmkim/BaekJoon/\353\260\261\354\244\200_2533.py" @@ -0,0 +1,30 @@ +import sys +input = sys.stdin.readline +sys.setrecursionlimit(10**9) +n = int(input()) +tree = [[] for _ in range(n+1)] +dp = [[0, 0] for _ in range(n + 1)] +visited = [0 for _ in range(n + 1)] + +for i in range(n-1): + a, b = map(int, input().split()) + + tree[a].append(b) + tree[b].append(a) + +#print(tree) + +def bfs(root): + visited[root] = True + dp[root][0] = 0 + dp[root][1] = 1 + + for i in tree[root]: + if not visited[i]: + bfs(i) + dp[root][0] += dp[i][1] + dp[root][1] += min(dp[i][0], dp[i][1]) + +bfs(1) + +print(min(dp[1][0], dp[1][1])) \ No newline at end of file diff --git "a/cmkim/BaekJoon/\353\260\261\354\244\200_2931.py" "b/cmkim/BaekJoon/\353\260\261\354\244\200_2931.py" new file mode 100644 index 0000000..de95a35 --- /dev/null +++ "b/cmkim/BaekJoon/\353\260\261\354\244\200_2931.py" @@ -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) diff --git "a/cmkim/BaekJoon/\353\260\261\354\244\200_5547.py" "b/cmkim/BaekJoon/\353\260\261\354\244\200_5547.py" new file mode 100644 index 0000000..bd666a0 --- /dev/null +++ "b/cmkim/BaekJoon/\353\260\261\354\244\200_5547.py" @@ -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)) From 2fa93fb03edec1c42bde4994b1b469e50a8f1b06 Mon Sep 17 00:00:00 2001 From: bsyzch <47052601+bsyzch@users.noreply.github.com> Date: Mon, 6 Sep 2021 23:46:26 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Delete=20=EB=B0=B1=EC=A4=80=201260.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200 1260.py" | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 "cmkim/BaekJoon/\353\260\261\354\244\200 1260.py" diff --git "a/cmkim/BaekJoon/\353\260\261\354\244\200 1260.py" "b/cmkim/BaekJoon/\353\260\261\354\244\200 1260.py" deleted file mode 100644 index 8df7e8a..0000000 --- "a/cmkim/BaekJoon/\353\260\261\354\244\200 1260.py" +++ /dev/null @@ -1,42 +0,0 @@ -from collections import deque -def DFS(v, visited): - - visited[v] = 1 - print(v, end=' ') # end= ' ' -> 다음 출력값 사이의 간격 조정(줄바꿈도 생략가능) - - for i in range(1, n+1): - - if not visited[i] and arr[v][i] == 1: - DFS(i, visited) - -def BFS(v, visited): - queue = deque([v]) - visited[v] = 1 - - while(queue): - v = queue.popleft() # 시작 기준이 되는 값을 잡고 시작한다. - print(v, end=' ') # end= ' ' -> 다음 출력값 사이의 간격 조정(줄바꿈도 생략가능) - for i in range(1, n+1): # 기준값 주변에 있는 방문하지 않은 값들을 전부 탐색한다. - if not visited[i] and arr[v][i] == 1: - queue.append(i) - visited[i] = 1 - - - -n, m, v = map(int, input().split()) - -arr = [[0]*(n+1) for _ in range(n+1)] -visited = [0]*(n+1) - -for i in range(m): - x, y = map(int, input().split()) - arr[x][y] = 1 - arr[y][x] = 1 - - - - -DFS(v, visited) #사용할 graph, 시작노드, 방문여부 -print('') -visited = [0]*(n+1) -BFS(v, visited) From 4a1a1102131f409a26ebce64b5a33392f8535acf Mon Sep 17 00:00:00 2001 From: bsyzch <47052601+bsyzch@users.noreply.github.com> Date: Mon, 6 Sep 2021 23:47:04 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Delete=20=EB=B0=B1=EC=A4=80=5F1062.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaekJoon/\353\260\261\354\244\200_1062.py" | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 "cmkim/BaekJoon/\353\260\261\354\244\200_1062.py" diff --git "a/cmkim/BaekJoon/\353\260\261\354\244\200_1062.py" "b/cmkim/BaekJoon/\353\260\261\354\244\200_1062.py" deleted file mode 100644 index b2a7d69..0000000 --- "a/cmkim/BaekJoon/\353\260\261\354\244\200_1062.py" +++ /dev/null @@ -1,16 +0,0 @@ -n, k = map(int, input().split()) - -arr = [] -teach = [] -for i in range(n): - arr.append(input()) -# for i in range(n): -# print(arr[i]) -for i in range(n): - teach.append(arr[i][4:-4]) -# for i in range(n): -# print(teach[i]) -for i in range(n): - teach[i] = set(teach[i]) -# for i in range(n): -# print(teach[i]) \ No newline at end of file