diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 73f69e0..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/algorithm-study.iml b/.idea/algorithm-study.iml deleted file mode 100644 index d0876a7..0000000 --- a/.idea/algorithm-study.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index ccffe40..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 7499006..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/source/HDG/220415/bj1260.md b/source/HDG/220415/bj1260.md deleted file mode 100644 index 370bbfb..0000000 --- a/source/HDG/220415/bj1260.md +++ /dev/null @@ -1,51 +0,0 @@ -## DFS와 BFS - -인접행렬과 dfs는 stack 자료구조를 사용하여 풀었습니다. - -```python -import sys -from collections import deque - -n, m, v = map(int,sys.stdin.readline().split()) -graph = [[] for _ in range(n+1)] - -for _ in range(m): - a, b = map(int, sys.stdin.readline().split()) - graph[a].append(b) - graph[b].append(a) - -def dfs(node): - stack = [node] - visited = [node] - - while stack: - target = stack.pop() - for i in sorted(graph[target]): - if i not in visited: - stack.append(target) - stack.append(i) - visited.append(i) - break - - print(' '.join(map(str, visited))) - return - - -def bfs(node): - queue = deque() - queue.append(node) - visited = [node] - - while queue: - target = queue.popleft() - for i in sorted(graph[target]): - if i not in visited: - queue.append(i) - visited.append(i) - - print(' '.join(map(str, visited))) - return - -dfs(v) -bfs(v) -``` diff --git a/source/HDG/220415/bj1260.py b/source/HDG/220415/bj1260.py deleted file mode 100644 index 2584266..0000000 --- a/source/HDG/220415/bj1260.py +++ /dev/null @@ -1,45 +0,0 @@ -import sys -from collections import deque - -n, m, v = map(int,sys.stdin.readline().split()) -graph = [[] for _ in range(n+1)] - -for _ in range(m): - a, b = map(int, sys.stdin.readline().split()) - graph[a].append(b) - graph[b].append(a) - -def dfs(node): - stack = [node] - visited = [node] - - while stack: - target = stack.pop() - for i in sorted(graph[target]): - if i not in visited: - stack.append(target) - stack.append(i) - visited.append(i) - break - - print(' '.join(map(str, visited))) - return - - -def bfs(node): - queue = deque() - queue.append(node) - visited = [node] - - while queue: - target = queue.popleft() - for i in sorted(graph[target]): - if i not in visited: - queue.append(i) - visited.append(i) - - print(' '.join(map(str, visited))) - return - -dfs(v) -bfs(v) \ No newline at end of file diff --git a/source/HDG/220416/bj1012.md b/source/HDG/220416/bj1012.md deleted file mode 100644 index a29b9cd..0000000 --- a/source/HDG/220416/bj1012.md +++ /dev/null @@ -1,44 +0,0 @@ -## 유기농 배추 - -dfs로 풀었습니다 -visited check는 숫자를 2로 표현해서 그래프 변수 하나로 처리했습니다 -개인적으로 이런 문제는 dfs보단 bfs가 직관적으로 풀 수 있을거 같아요 - -```python -import sys -sys.setrecursionlimit(10**6) - -def dfs(x,y, graph): - dx = [1,-1,0,0] - dy = [0,0,-1,1] - - for i in range(4): - nx = x + dx[i] - ny = y + dy[i] - if 0 <= nx < n and 0 <= ny < m and graph[nx][ny] == 1: - graph[nx][ny] = 2 - graph = dfs(nx,ny,graph) - - return graph - - -for _ in range(int(sys.stdin.readline())): - m, n, cabbage = map(int, sys.stdin.readline().split()) - graph = [[0] * m for __ in range(n)] - count = 0 - - # 그래프 생성 - for i in range(cabbage): - x, y = map(int, sys.stdin.readline().split()) - graph[y][x] = 1 - - # 모든 좌표 처리 - for x in range(n): - for y in range(m): - if graph[x][y] == 1: - graph[x][y] = 2 - count+=1 - graph = dfs(x,y,graph) - - print(count) -``` diff --git a/source/HDG/220416/bj1012.py b/source/HDG/220416/bj1012.py deleted file mode 100644 index f7ec765..0000000 --- a/source/HDG/220416/bj1012.py +++ /dev/null @@ -1,43 +0,0 @@ -# -*- coding: UTF-8 -*- -''' -@Project :algorithm-study -@File :bj1012.py -@IDE :PyCharm -@Author : Hwang -@Date :2022-04-16 오후 11:32 -''' - -import sys -sys.setrecursionlimit(10**6) - -def dfs(x,y, graph): - dx = [1,-1,0,0] - dy = [0,0,-1,1] - - for i in range(4): - nx = x + dx[i] - ny = y + dy[i] - if 0 <= nx < n and 0 <= ny < m and graph[nx][ny] == 1: - graph[nx][ny] = 2 - graph = dfs(nx,ny,graph) - - return graph - - -for _ in range(int(sys.stdin.readline())): - m, n, cabbage = map(int, sys.stdin.readline().split()) - graph = [[0] * m for __ in range(n)] - count = 0 - - for i in range(cabbage): - x, y = map(int, sys.stdin.readline().split()) - graph[y][x] = 1 - - for x in range(n): - for y in range(m): - if graph[x][y] == 1: - graph[x][y] = 2 - count+=1 - graph = dfs(x,y,graph) - - print(count) \ No newline at end of file diff --git a/source/HDG/220418/bj11724.md b/source/HDG/220418/bj11724.md deleted file mode 100644 index a57ec7e..0000000 --- a/source/HDG/220418/bj11724.md +++ /dev/null @@ -1,34 +0,0 @@ -## 연결 요소의 개수 - -union-find 사용 - -```python -import sys - -def find(parent, x): - if parent[x] == x: - return x - return find(parent, parent[x]) - -def union(parent, x, y): - x = find(parent, x) - y = find(parent, y) - if x < y: - parent[y] =x - else: - parent[x] =y - -vertex, edge = map(int, sys.stdin.readline().split()) -graph = [[] for _ in range(vertex+1)] -parent = [ i for i in range(vertex+1)] - -for _ in range(edge): - a, b = map(int, sys.stdin.readline().split()) - union(parent, a, b) - -result = [] -for i in parent[1:]: - result.append(find(parent,i)) - -print(len(set(result))) -``` diff --git a/source/HDG/220418/bj11724.py b/source/HDG/220418/bj11724.py deleted file mode 100644 index 82aafbd..0000000 --- a/source/HDG/220418/bj11724.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: UTF-8 -*- -''' -@Project :algorithm-study -@File :bj11724.py -@IDE :PyCharm -@Author : Hwang -@Date :2022-04-18 오후 6:48 -''' - -import sys - -def find(parent, x): - if parent[x] == x: - return x - return find(parent, parent[x]) - -def union(parent, x, y): - x = find(parent, x) - y = find(parent, y) - if x < y: - parent[y] =x - else: - parent[x] =y - -vertex, edge = map(int, sys.stdin.readline().split()) -graph = [[] for _ in range(vertex+1)] -parent = [ i for i in range(vertex+1)] - -for _ in range(edge): - a, b = map(int, sys.stdin.readline().split()) - union(parent, a, b) - -result = [] -for i in parent[1:]: - result.append(find(parent,i)) - -print(len(set(result))) \ No newline at end of file diff --git a/source/HDG/220418/bj2667.md b/source/HDG/220418/bj2667.md deleted file mode 100644 index 34b9510..0000000 --- a/source/HDG/220418/bj2667.md +++ /dev/null @@ -1,44 +0,0 @@ -## 단지번호붙이기 - -bfs 사용 - -```python -import sys -from collections import deque - -n = int(sys.stdin.readline()) -graph = [] -total = 0 -amount = [] -dx = [0,0,-1,1] -dy = [1,-1,0,0] - -for _ in range(n): - graph.append(list(map(int,sys.stdin.readline().split()[0]))) - -def bfs(x,y): - count = 1 - q = deque([[x,y]]) - while q: - x, y = q.popleft() - for i in range(4): - nx = x + dx[i] - ny = y + dy[i] - if 0<=nx b: - q.append([x+y-b, b, z]) - else: - q.append([0, x+y ,z]) - if x+z > c: - q.append([x+z-c, y, c]) - else: - q.append([0, y, x+z]) - if y+x > a: - q.append([a, y+x-a, z]) - else: - q.append([y+x, 0, z]) - if y+z > c: - q.append([x,y+z-c, c]) - else: - q.append([x,0,y+z]) - if z+x > a: - q.append([a,y,z+x-a]) - else: - q.append([z+x, y, 0]) - if z+y > b: - q.append([x,b,z+y-b]) - else: - q.append([x, z+y, 0]) - -bfs(a,b,c) -for i in range(201): - if answer[i]: - print(i, end=" ") -``` diff --git a/source/HDG/220419/bj2251.py b/source/HDG/220419/bj2251.py deleted file mode 100644 index 02b6599..0000000 --- a/source/HDG/220419/bj2251.py +++ /dev/null @@ -1,56 +0,0 @@ -# -*- coding: UTF-8 -*- -''' -@Project :algorithm-study -@File :bj2251.py -@IDE :PyCharm -@Author : Hwang -@Date :2022-04-19 오후 11:15 -''' - -import sys -from collections import deque - -a, b, c = map(int,sys.stdin.readline().split()) -check = [[0]*201 for i in range(201)] -answer = [ 0 for _ in range(201)] - -def bfs(a,b,c): - q = deque() - q.append([0,0,c]) - while q: - x, y, z = q.popleft() - if check[x][y] == 1: - continue - check[x][y] = 1 - if x == 0: - answer[z] = 1 - - if x+y > b: - q.append([x+y-b, b, z]) - else: - q.append([0, x+y ,z]) - if x+z > c: - q.append([x+z-c, y, c]) - else: - q.append([0, y, x+z]) - if y+x > a: - q.append([a, y+x-a, z]) - else: - q.append([y+x, 0, z]) - if y+z > c: - q.append([x,y+z-c, c]) - else: - q.append([x,0,y+z]) - if z+x > a: - q.append([a,y,z+x-a]) - else: - q.append([z+x, y, 0]) - if z+y > b: - q.append([x,b,z+y-b]) - else: - q.append([x, z+y, 0]) - -bfs(a,b,c) -for i in range(201): - if answer[i]: - print(i, end=" ") \ No newline at end of file