diff --git a/.gitignore b/.gitignore index 136797b..d7a5c87 100644 --- a/.gitignore +++ b/.gitignore @@ -90,4 +90,8 @@ modules.xml .idea/misc.xml *.ipr -# End of https://www.toptal.com/developers/gitignore/api/intellij+iml \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/intellij+iml + +test.js +test.py + diff --git a/divide_and_conquer/1780/seungoh1780.py b/divide_and_conquer/1780/seungoh1780.py new file mode 100644 index 0000000..a8a81a6 --- /dev/null +++ b/divide_and_conquer/1780/seungoh1780.py @@ -0,0 +1,61 @@ +import sys + +N = int(sys.stdin.readline()) +answerArr = [0, 0, 0] + +graph = [[] for _ in range(N)] + +for i in range(N): + graph[i] = list(map(int, sys.stdin.readline().split())) + +# 전체 동일한 숫자만 있는지 체크, 동일하면 해당 숫자를, 없으면 -2를 리턴 +def check_box(graph, x, y, length): + k = graph[x][y] + for i in range(x, x+length): + for j in range(y, y+length): + if graph[i][j] != k: + return -2 + return k + +# 9개의 작은 박스로 나누기. 3 나눗셈을 활용하여 어디 집어넣을지 계산 +def divide(box): + K = len(box) + division = K // 3 + small_box_list = [ + [[0 for _ in range(division)] for _ in range(division)] for _ in range(9) + ] + + for i in range(K): + for j in range(K): + x = i // division + y = j // division + box_num = 3 * x + y + box_x = i % division + box_y = j % division + small_box_list[box_num][box_x][box_y] = box[i][j] + + return small_box_list + +# 현재 박스를 체크해본뒤, 동일 숫자면 answerArr 업데이트 & 아니면 9개로 나눠서 재귀반복 실행 +def main(graph, x, y, length): + check_num = check_box(graph, x, y, length) + if check_num == -2: + division = length // 3 + main(graph, x, y, division) + main(graph, x + (division * 1), y, division) + main(graph, x + (division * 2), y, division) + main(graph, x, y + (division * 1), division) + main(graph, x + (division * 1), y + (division * 1), division) + main(graph, x + (division * 2), y + (division * 1), division) + main(graph, x, y + (division * 2), division) + main(graph, x + (division * 1), y + (division * 2), division) + main(graph, x + (division * 2), y + (division * 2), division) + + else: + answerArr[check_num+1] += 1 + + +main(graph, 0, 0, len(graph)) + +for answer in answerArr: + print(answer) \ No newline at end of file diff --git a/divide_and_conquer/18222/seungoh18222.py b/divide_and_conquer/18222/seungoh18222.py new file mode 100644 index 0000000..59b9c69 --- /dev/null +++ b/divide_and_conquer/18222/seungoh18222.py @@ -0,0 +1,25 @@ +import sys +import math + +K = int(sys.stdin.readline()) +count = 0 + +def downgrade(): + global K + global count + x = 1 + N = 0 + while N < K: + N = math.pow(2, x) + x += 1 + N = int(N // 2) + K = K - N + count += 1 + +while K != 1: + downgrade() + +if(count % 2 == 0): + print(0) +else: + print(1) \ No newline at end of file diff --git a/graph2/1260/seungoh.py b/graph2/1260/seungoh.py new file mode 100644 index 0000000..7094af6 --- /dev/null +++ b/graph2/1260/seungoh.py @@ -0,0 +1,41 @@ +import sys +from collections import deque + +def dfs(graph, n, visited): + visited[n] = True + print(n, end=" ") + if len(graph[n]) == 0: + return + for i in graph[n]: + if not visited[i]: + dfs(graph, i, visited) + +def bfs(graph, start, visited): + queue = deque([start]) + visited[start] = True + print("") + print(start, end=" ") + while queue: + v = queue.popleft() + if len(graph[n]) == 0: + return + for i in graph[v]: + if not visited[i]: + queue.append(i) + visited[i] = True + print(i, end=" ") + print("") + +n, m, start = map(int, sys.stdin.readline().split()) +visited = [False] * (n+1) +graph = [[] for _ in range(n+1)] +for _ in range(m): + x, y = map(int, sys.stdin.readline().split()) + graph[x].append(y) + graph[y].append(x) +for i in range(len(graph)): + graph[i].sort() + +dfs(graph, start, visited) +visited = [False] * (n+1) +bfs(graph, start, visited) diff --git a/graph2/1325/seungoh.py b/graph2/1325/seungoh.py new file mode 100644 index 0000000..62d228f --- /dev/null +++ b/graph2/1325/seungoh.py @@ -0,0 +1,51 @@ +import sys +from collections import deque + +INF = int(1e9) + +N, M = map(int, sys.stdin.readline().split()) + +graph = [[] for _ in range(N+1)] +distance = [-1] * (N+1) +visited = [False] * (N+1) + +for _ in range(M): + a, b = map(int, sys.stdin.readline().split()) + graph[a].append(b) + +def bfs(graph, start, visited): + queue = deque([start]) + visited[start] = True + while queue: + v = queue.popleft() + if len(graph[n]) == 0: + return + for i in graph[v]: + if not visited[i]: + queue.append(i) + visited[i] = True + + +def get_biggest_node(): + max_value = -1 + index = 0 + for i in range(N+1): + if distance[i] > max_value and not visited[i]: + max_value = distance[i] + index = i + return index + +def dijkstra(start): + distance[start] = 0 + visited[start] = True + for k in graph[start]: + distance[k] = 1 + + for i in range(N-1): + now = get_biggest_node() + + visited[now] = True + for j in graph[now]: + cost = distance[now] + 1 + + diff --git a/graph2/17070/seungoh.py b/graph2/17070/seungoh.py new file mode 100644 index 0000000..2c8f3b0 --- /dev/null +++ b/graph2/17070/seungoh.py @@ -0,0 +1,16 @@ +import sys + +N = int(sys.stdin.readline()) +graph = [] + +for _ in range(N): + graph.append(list(map(lambda a: [int(a), dict({ + 'H': 0, + 'V': 0, + 'D': 0 + })], sys.stdin.readline().split()))) + +graph[0][1][1]['H'] = 1 +print(graph) + +## bfs 갈 수 있는 후보지는 3개 diff --git a/graph2/2178/seungoh.py b/graph2/2178/seungoh.py new file mode 100644 index 0000000..4e6fdcc --- /dev/null +++ b/graph2/2178/seungoh.py @@ -0,0 +1,32 @@ +import sys +from collections import deque + +N, M = map(int, sys.stdin.readline().split()) +graph = [[] for _ in range(N)] + +for i in range(N): + x = sys.stdin.readline() + for j in range(len(x) - 1): + graph[i].append(int(x[j])) + +dx = [1, 0, -1, 0] +dy = [0, 1, 0, -1] + +def bfs(x, y): + queue = deque() + queue.append((x, y)) + while queue: + x, y = queue.popleft() + for k in range(4): + nx = x + dx[k] + ny = y + dy[k] + if nx < 0 or nx > (N-1) or ny < 0 or ny > (M-1): + continue + if graph[nx][ny] == 0: + continue + if graph[nx][ny] == 1: + queue.append((nx, ny)) + graph[nx][ny] = graph[x][y] + 1 + return graph[N-1][M-1] + +print(bfs(0,0)) \ No newline at end of file diff --git a/graph2/7562/seungoh.py b/graph2/7562/seungoh.py new file mode 100644 index 0000000..c48ee2f --- /dev/null +++ b/graph2/7562/seungoh.py @@ -0,0 +1,43 @@ +### 시간 초과 ㅠㅠ ### +import sys +from collections import deque + +def bfs(x, y): + if start == end: + return 0 + queue = deque() + queue.append((x, y)) + stop = False + while queue: + x, y = queue.popleft() + for k in range(8): + nx = x + dx[k] + ny = y + dy[k] + if nx < 0 or nx > (N-1) or ny < 0 or ny > (N-1): + continue + if graph[nx][ny] == 0: + queue.append((nx, ny)) + graph[nx][ny] = graph[x][y] + 1 + if [nx, ny] == end: + stop = True + break + if stop: + break + return graph[end[0]][end[1]] + +answers = [] +X = int(sys.stdin.readline()) + +for _ in range(X): + N = int(sys.stdin.readline()) + start = list(map(int, sys.stdin.readline().split())) + end = list(map(int, sys.stdin.readline().split())) + graph = [[0 for _ in range(N)] for _ in range(N)] + + dx = [1, 1, 2, 2, -1, -1, -2, -2] + dy = [-2, 2, -1, 1, -2, 2, -1, 1] + + answers.append(bfs(start[0], start[1])) + +for answer in answers: + print(answer) \ No newline at end of file