diff --git "a/00\354\243\274\354\260\250(\355\205\234\355\224\214\353\246\277)/README.md" "b/00\354\243\274\354\260\250(\355\205\234\355\224\214\353\246\277)/README.md" new file mode 100644 index 0000000..642e2f6 --- /dev/null +++ "b/00\354\243\274\354\260\250(\355\205\234\355\224\214\353\246\277)/README.md" @@ -0,0 +1,38 @@ +> 마크다운 사용법 링크: https://gist.github.com/ihoneymon/652be052a0727ad59601 +## 숙제 +|난이도|번호|제목|링크| +|-|-|-|-| +||번||https://www.acmicpc.net/problem/| +||번||https://www.acmicpc.net/problem/| + +## 스터디 진행 중 풀이 +|난이도|번호|제목|링크| +|-----|-----|----------|----------------------------------------| +|난이도|번호|제목|링크| +|골드 4|번||https://www.acmicpc.net/problem/| + + +## 찾아온 문제들 +#### 민기홍 +|난이도|번호|제목|링크| +|-----|-----|---------------------|----------------------------------------| +|골드 4|번||https://www.acmicpc.net/problem/| +|골드 5|번||https://www.acmicpc.net/problem/| + +#### 김동주 +|난이도|번호|제목|링크| +|-----|-----|---------------------|----------------------------------------| +|골드 4|번||https://www.acmicpc.net/problem/| +|골드 5|번||https://www.acmicpc.net/problem/| + +#### 정우현 +|난이도|번호|제목|링크| +|-----|-----|---------------------|----------------------------------------| +|골드 4|번||https://www.acmicpc.net/problem/| +|골드 5|번||https://www.acmicpc.net/problem/| + +#### 서동혁 +|난이도|번호|제목|링크| +|-----|-----|---------------------|----------------------------------------| +|골드 4|번||https://www.acmicpc.net/problem/| +|골드 5|번||https://www.acmicpc.net/problem/| diff --git "a/01\354\243\274\354\260\250 (\354\240\225\353\240\254)/README.md" "b/01\354\243\274\354\260\250 (\354\240\225\353\240\254)/README.md" new file mode 100644 index 0000000..e2cf9e3 --- /dev/null +++ "b/01\354\243\274\354\260\250 (\354\240\225\353\240\254)/README.md" @@ -0,0 +1,3 @@ +유형: 정렬(선택, 버블, 삽입, 쾌속, 합병) + 시간복잡도 계산 + +2750번, 2751번 문제 diff --git "a/01\354\243\274\354\260\250/2750.py" "b/01\354\243\274\354\260\250/2750.py" new file mode 100644 index 0000000..4c2be30 --- /dev/null +++ "b/01\354\243\274\354\260\250/2750.py" @@ -0,0 +1,27 @@ +# O(N^2)의 시간복잡도를 하기 위해 선택정렬 코드 + +# A개의 정수를 입력 +A = int(input()) + +# 입력된 정수를 저장할 빈 리스트 A_list를 초기화시키기 +A_list = [] + +# A번 반복하여 정수를 사용자로부터 입력받고 A_list 리스트에 저장 +for i in range(A): + num = int(input()) + A_list.append(num) + +# 선택 정렬을 이용하여 리스트를 정렬 +for i in range(A): + # 현재 위치부터 나머지 원소 중에서 최솟값의 인덱스 찾기 + min_index = i + for j in range(i + 1, A): + if A_list[j] < A_list[min_index]: + min_index = j + + # 현재 위치의 원소와 최솟값의 원소를 교환 + A_list[i], A_list[min_index] = A_list[min_index], A_list[i] + +# 정렬된 리스트를 출력 +for i in A_list: + print(i) diff --git "a/01\354\243\274\354\260\250/2751.py" "b/01\354\243\274\354\260\250/2751.py" new file mode 100644 index 0000000..1624ac5 --- /dev/null +++ "b/01\354\243\274\354\260\250/2751.py" @@ -0,0 +1,39 @@ +# O(n log n)의 시간 복잡도를 위해 quick_sort 함수 사용 +def quick_sort(arr): + if len(arr) <= 1: + return arr + + # 피벗 원소를 선택 + pivot = arr[len(arr) // 2] + + # 피벗보다 작은 원소들 (왼쪽) + left = [x for x in arr if x < pivot] + + # 피벗과 같은 원소들 (가운데) + middle = [x for x in arr if x == pivot] + + # 피벗보다 큰 원소들 (오른쪽) + right = [x for x in arr if x > pivot] + + return quick_sort(left) + middle + quick_sort(right) + +# 사용자로부터 요소의 개수인 A를 입력받기 +A = int(input()) + +# 사용자 입력을 저장할 빈 리스트를 초기화 +A_list = [] + + +# A개의 정수를 사용자로부터 입력받고 A_list에 저장 +for i in range(A): + num = int(input()) + A_list.append(num) + +# quick_sort 함수를 사용하여 리스트를 정렬 +A_list = quick_sort(A_list) + +# 정렬된 리스트 출력 +for i in A_list: + print(i) + + diff --git "a/02\354\243\274\354\260\250/1920\353\262\210.py" "b/02\354\243\274\354\260\250/1920\353\262\210.py" new file mode 100644 index 0000000..6c131f4 --- /dev/null +++ "b/02\354\243\274\354\260\250/1920\353\262\210.py" @@ -0,0 +1,30 @@ +def binary_search(array, elem): + #left, right 값 초기화 + left, right = 0, len(array) - 1 + + #왼쪽 인덱스가 오른쪽 인덱스보다 작거나 같을 동안 반복 + while left <= right: + mid = (left + right) // 2 + #중간 값이 찾고자 하는 값과 같다면, 1 반환하고 종료 + if array[mid] == elem: + return 1 + #만약 중간 값이 찾는 값보다 작다면, 왼쪽 범위를 중간 값의 오른쪽으로 1씩 조정 + elif array[mid] < elem: + left = mid + 1 + #중간 값이 찾고자 하는 값보다 크다면, 오른쪽 범위를 중간 값의 왼쪽으로 1씩 조정 + else: + right = mid - 1 + return 0 + +#입력으로부터 정수 n 받기 +n = int(input()) +a_list = list(map(int, input().split())) +#입력으로부터 정수 m 받기 +m = int(input()) +x_list = list(map(int, input().split())) + +#리스트 정렬 +a_list.sort() + +for x in x_list: + print(binary_search(a_list, x)) diff --git "a/02\354\243\274\354\260\250/2110\353\262\210.py" "b/02\354\243\274\354\260\250/2110\353\262\210.py" new file mode 100644 index 0000000..68c6af9 --- /dev/null +++ "b/02\354\243\274\354\260\250/2110\353\262\210.py" @@ -0,0 +1,38 @@ +import sys + +input = sys.stdin.readline +# map 함수를 사용하여 입력된 값을 공백 기준으로 나눈 결과를 정수로 변환하여 각각 저장 +N, C = map(int, input().split()) +#N개의 집 좌표를 입력받고, 각 좌표를 정수로 변환 후 sorted 함수로 정렬하여 home에 저장 +home = sorted([int(input()) for _ in range(N)]) + +# 공유기가 설치될 수 있는 최대 거리를 받아 해당 거리로 공유기를 설치했을 때의 개수를 세는 함수를 정의 +# count 는 공유기의 개수 저장, current 는 현재 집의 좌표 +def count_routers(distance): + count, current = 1, home[0] + + for h in home: + if h - current >= distance: + count += 1 + current = h + + return count + +# 이진 탐색을 위한 시작점과 끝점 설정, 시작점은 항상 1, 끝점은 정렬된 집의 좌표 중 가장 뒤에 있는 좌표에서 가장 앞에 있는 좌표를 뺀 값 +start, end = 1, home[-1] - home[0] +# result 는 공유기 사이의 최대 거 +result = 0 + +# 시작점이 끝점보다 작거나 같은 동안 계속 반복, 중간지점 mid 계산 +while start <= end: + mid = (start + end) // 2 + +# 중간 지점으로 공유기를 설치했을 때의 개수가 목표 개수보다 크거나 같다면, 현재의 중간 값을 결과로 저장 + # 시작점을 중간값보다 +1로 갱신, 그렇지 않다면 끝점을 중간 값보다 -1로 갱신 + if count_routers(mid) >= C: + result = mid + start = mid + 1 + else: + end = mid - 1 + +print(result) diff --git "a/03\354\243\274\354\260\250/1260\353\262\210.py" "b/03\354\243\274\354\260\250/1260\353\262\210.py" new file mode 100644 index 0000000..901fb80 --- /dev/null +++ "b/03\354\243\274\354\260\250/1260\353\262\210.py" @@ -0,0 +1,47 @@ +from collections import deque + +#그래프, 시작노드, 방문 여부 나타내는 배열을 인자로 받기 - 깊이 우선 탐색 +def dfs(graph, start, visited): + print(start, end=' ') + visited[start] = True #노드 방문 완료 + +# 현재 노드에 연결된 이웃 노드들 순회 (정렬된 순서로 방문하기 위해 sorted()함수 사용) + for neighbor in sorted(graph[start]): + if not visited[neighbor]: + dfs(graph, neighbor, visited) # 이웃 노드가 방문되지 않을 시 DFS 함수를 재귀적으로 호출하여 해당 이웃 방문 +# 너비 우선 탐색 +def bfs(graph, start, visited): + queue = deque([start]) # BFS에서 사용할 큐 초기화 - 시작 노드로 큐 초기화 + visited[start] = True + + while queue: # 큐가 비어 있지 않는 동안 반복 + node = queue.popleft() # 큐의 맨 앞에서 노드 꺼내기 + print(node, end=' ') #현재 노드를 출력 + + for neighbor in sorted(graph[node]): + if not visited[neighbor]: + queue.append(neighbor) + visited[neighbor] = True + +# 입력 받기 (정점의 개수 - N, 간선의 개수 - M, 시작 노드 - V) +N, M, V = map(int, input().split()) + +# 1부터 N까지의 정점을 갖는 빈 그래프를 초기화 +graph = {i: set() for i in range(1, N + 1)} + +#간선 정보를 입력받아 양방향 그래프 만들기 +for _ in range(M): + a, b = map(int, input().split()) + graph[a].add(b) + graph[b].add(a) + +# DFS와 BFS에서 사용할 방문 여부를 나타내는 배열을 초기화 +visited_dfs = [False] * (N + 1) +visited_bfs = [False] * (N + 1) + +# DFS 수행 +dfs(graph, V, visited_dfs) +print() + +# BFS 수행 +bfs(graph, V, visited_bfs) diff --git "a/04\354\243\274\354\260\250/11047\353\262\210.py" "b/04\354\243\274\354\260\250/11047\353\262\210.py" new file mode 100644 index 0000000..37b1fec --- /dev/null +++ "b/04\354\243\274\354\260\250/11047\353\262\210.py" @@ -0,0 +1,20 @@ +def min_coin_count(N, K, coin_values): + count = 0 + + # 가장 큰 가치의 동전부터 차례로 사용하여 K를 만듦 + for i in range(N-1, -1, -1): + if K == 0: + break + if K >= coin_values[i]: + count += K // coin_values[i] + K %= coin_values[i] + + return count + +# 입력 받기 +N, K = map(int, input().split()) +coin_values = [int(input()) for _ in range(N)] + +# 필요한 동전 개수의 최솟값 계산 및 출력 +result = min_coin_count(N, K, coin_values) +print(result) diff --git "a/04\354\243\274\354\260\250/2875\353\262\210.py" "b/04\354\243\274\354\260\250/2875\353\262\210.py" new file mode 100644 index 0000000..50d6f25 --- /dev/null +++ "b/04\354\243\274\354\260\250/2875\353\262\210.py" @@ -0,0 +1,17 @@ +def max_teams(N, M, K): + # 가능한 최대 팀 수 계산 + teams = 0 + + # 여학생과 남학생 중 적은 수의 인원을 기준으로 팀을 구성 + while N >= 2 and M >= 1 and N + M >= K + 3: + N -= 2 + M -= 1 + teams += 1 + + return teams +# 입력 받기 +N, M, K = map(int, input().split()) + +# 최대 팀 수 계산 및 출력 +result = max_teams(N, M, K) +print(result) diff --git "a/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/README.md" "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/README.md" new file mode 100644 index 0000000..9da5951 --- /dev/null +++ "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/README.md" @@ -0,0 +1,10 @@ +숙제 +|난이도|번호|제목|링크| +|-----|-----|----------|----------------------------------------| +|실버 1|2178번|미로 탐색|https://www.acmicpc.net/problem/2178| +|실버 3|2606번|바이러스|https://www.acmicpc.net/problem/2606| + +스터디 진행 중 풀이 +|난이도|번호|제목|링크| +|-----|-----|----------|----------------------------------------| +|실버 2|1012번|유기농 배추|https://www.acmicpc.net/problem/1012| diff --git "a/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\352\271\200\354\204\234\354\230\201/1012.py" "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\352\271\200\354\204\234\354\230\201/1012.py" new file mode 100644 index 0000000..f514c66 --- /dev/null +++ "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\352\271\200\354\204\234\354\230\201/1012.py" @@ -0,0 +1,40 @@ +T = int(input()) #테스트케이스의 개수 + +dx = [-1,1,0,0] +dy = [0,0,-1,1] + +def BFS(x,y): + queue = [(x,y)] + matrix[x][y] = 0 # 방문처리 + + while queue: + x,y = queue.pop(0) + + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + + if nx < 0 or nx >= M or ny < 0 or ny >= N: + continue + + if matrix[nx][ny] == 1 : + queue.append((nx,ny)) + matrix[nx][ny] = 0 + +# 행렬만들기 +for i in range(T): + M, N, K = map(int,input().split()) + matrix = [[0]*(N) for _ in range(M)] + cnt = 0 + + for j in range(K): + x,y = map(int, input().split()) + matrix[x][y] = 1 + + for a in range(M): + for b in range(N): + if matrix[a][b] == 1: + BFS(a,b) + cnt += 1 + + print(cnt) \ No newline at end of file diff --git "a/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\352\271\200\354\204\234\354\230\201/README.md" "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\352\271\200\354\204\234\354\230\201/README.md" new file mode 100644 index 0000000..8b13789 --- /dev/null +++ "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\352\271\200\354\204\234\354\230\201/README.md" @@ -0,0 +1 @@ + diff --git "a/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\353\257\274\352\270\260\355\231\215/1012.py" "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\353\257\274\352\270\260\355\231\215/1012.py" new file mode 100644 index 0000000..f514c66 --- /dev/null +++ "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\353\257\274\352\270\260\355\231\215/1012.py" @@ -0,0 +1,40 @@ +T = int(input()) #테스트케이스의 개수 + +dx = [-1,1,0,0] +dy = [0,0,-1,1] + +def BFS(x,y): + queue = [(x,y)] + matrix[x][y] = 0 # 방문처리 + + while queue: + x,y = queue.pop(0) + + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + + if nx < 0 or nx >= M or ny < 0 or ny >= N: + continue + + if matrix[nx][ny] == 1 : + queue.append((nx,ny)) + matrix[nx][ny] = 0 + +# 행렬만들기 +for i in range(T): + M, N, K = map(int,input().split()) + matrix = [[0]*(N) for _ in range(M)] + cnt = 0 + + for j in range(K): + x,y = map(int, input().split()) + matrix[x][y] = 1 + + for a in range(M): + for b in range(N): + if matrix[a][b] == 1: + BFS(a,b) + cnt += 1 + + print(cnt) \ No newline at end of file diff --git "a/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\353\257\274\352\270\260\355\231\215/2178.py" "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\353\257\274\352\270\260\355\231\215/2178.py" new file mode 100644 index 0000000..3d8c07b --- /dev/null +++ "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\353\257\274\352\270\260\355\231\215/2178.py" @@ -0,0 +1,46 @@ +from collections import deque + +N, M = map(int, input().split()) + +graph = [] + +for _ in range(N): + graph.append(list(map(int, input()))) + + +# 너비 우선 탐색 +def bfs(x, y): + # 이동할 네 가지 방향 정의 (상, 하, 좌, 우) + dx = [-1, 1, 0, 0] + dy = [0, 0, -1, 1] + + # deque 생성 + queue = deque() + queue.append((x, y)) + + while queue: + x, y = queue.popleft() + + # 현재 위치에서 4가지 방향으로 위치 확인 + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + + # 위치가 벗어나면 안되기 때문에 조건 추가 + if nx < 0 or nx >= N or ny < 0 or ny >= M: + continue + + # 벽이므로 진행 불가 + if graph[nx][ny] == 0: + continue + + # 벽이 아니므로 이동 + if graph[nx][ny] == 1: + graph[nx][ny] = graph[x][y] + 1 + queue.append((nx, ny)) + + # 마지막 값에서 카운트 값을 뽑는다. + return graph[N - 1][M - 1] + + +print(bfs(0, 0)) \ No newline at end of file diff --git "a/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\353\257\274\352\270\260\355\231\215/2606.py" "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\353\257\274\352\270\260\355\231\215/2606.py" new file mode 100644 index 0000000..ae96e76 --- /dev/null +++ "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\353\257\274\352\270\260\355\231\215/2606.py" @@ -0,0 +1,21 @@ +computer = int(input()) #컴퓨터 개수 +linked = int(input()) # 연결된 개수 +graph = [[] for i in range(computer+1)] #그래프 초기화 +visited = [0]*(computer+1) # 방문처리 리스트 + +for i in range(linked): + node1,node2 = map(int, input().split()) + graph[node1] += [node2] # 각 노드 연결 + graph[node2] += [node1] + +# bfs +Q = [1] # 큐 생성 +visited[1] = 1 # 1번부터 시작 +while Q: + current = Q.pop() + for i in graph[current]: + if visited[i] == 0: + Q.append(i) + visited[i] = 1 + +print(sum(visited)-1) \ No newline at end of file diff --git "a/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\353\257\274\352\270\260\355\231\215/README.md" "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\353\257\274\352\270\260\355\231\215/README.md" new file mode 100644 index 0000000..67305d9 --- /dev/null +++ "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\353\257\274\352\270\260\355\231\215/README.md" @@ -0,0 +1 @@ +테스트 용 diff --git "a/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\354\204\234\353\217\231\355\230\201/README.md" "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\354\204\234\353\217\231\355\230\201/README.md" new file mode 100644 index 0000000..67305d9 --- /dev/null +++ "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\354\204\234\353\217\231\355\230\201/README.md" @@ -0,0 +1 @@ +테스트 용 diff --git "a/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\354\240\225\354\232\260\355\230\204/README.md" "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\354\240\225\354\232\260\355\230\204/README.md" new file mode 100644 index 0000000..67305d9 --- /dev/null +++ "b/07\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211_bfs_dfs/\354\240\225\354\232\260\355\230\204/README.md" @@ -0,0 +1 @@ +테스트 용 diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/README.md" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/README.md" new file mode 100644 index 0000000..04af1da --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/README.md" @@ -0,0 +1,11 @@ +숙제 +|난이도|번호|제목|링크| +|-----|-----|---------------------|----------------------------------------| +|실버 1|2667번|단지번호붙이기|https://www.acmicpc.net/problem/2667| +|실버 1|2583번|영역 구하기|https://www.acmicpc.net/problem/2583| +|실버 2|18352번|특정 거리의 도시 찾기|https://www.acmicpc.net/problem/18352| + +스터디 진행 중 풀이 +|난이도|번호|제목|링크| +|-----|-----|----------|----------------------------------------| +|난이도|번호|제목|링크| diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\352\271\200\354\204\234\354\230\201/18352\353\262\210.py" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\352\271\200\354\204\234\354\230\201/18352\353\262\210.py" new file mode 100644 index 0000000..c1ddc52 --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\352\271\200\354\204\234\354\230\201/18352\353\262\210.py" @@ -0,0 +1,41 @@ +import sys +from collections import deque +input = sys.stdin.readline + +N, M, K, X = map(int, input().split()) +#0이 아니라 빈 리스트로 초기화되기 때문에, 각 도시에서 출발하는 도로의 목록을 담는 그래프를 나타내기 위한 초기화 +graph = [[] for _ in range(N + 1)] +#0으로 초기화된 리스트를 생성하되, 반복 변수가 필요하지 않다는 것을 나타내기 위해 _를 사용한 것 +visited = [0 for _ in range(N + 1)] + +for _ in range(M): + A, B = map(int, input().split()) + graph[A].append(B) + +result = [] + +def bfs(start): + queue = deque([start]) + visited[start] = 1 + + while queue: + current_city = queue.popleft() + #현재 도시까지의 거리가 k+1이라면(bfs 탐색의 k번째 단계에 도달했다면, 해당 도시를 결과 리스트에 추가 + if visited[current_city] == K + 1: + result.append(current_city) + continue + for neighbor in graph[current_city]: + #이웃 도시가 아직 방문되지 않았을 경우, 해당 도시 큐에 추가 + if visited[neighbor] == 0: + queue.append(neighbor) + visited[neighbor] = visited[current_city] + 1 + +#시작 도시 x에서부터 bfs탐색 +bfs(X) + +if len(result) == 0: + print(-1) +else: + result.sort() + for city in result: + print(city) diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\352\271\200\354\204\234\354\230\201/2583\353\262\210.py" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\352\271\200\354\204\234\354\230\201/2583\353\262\210.py" new file mode 100644 index 0000000..9105589 --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\352\271\200\354\204\234\354\230\201/2583\353\262\210.py" @@ -0,0 +1,39 @@ +import sys +sys.setrecursionlimit(10**6) + +def explore(x, y): + visited[x][y] = 1 + region_size[0] += 1 + dx = [-1, 0, 0, 1] + dy = [0, 1, -1, 0] + + for i in range(4): + nx, ny = x + dx[i], y + dy[i] + if 0 <= nx < N and 0 <= ny < M and visited[nx][ny] == 0: + explore(nx, ny) + +region_size = [0] +N, M, K = map(int, sys.stdin.readline().split()) +visited = [[0] * M for _ in range(N)] + +for _ in range(K): + x1, y1, x2, y2 = map(int, sys.stdin.readline().split()) + for j in range(y1, y2): + for k in range(x1, x2): + visited[j][k] = 1 + +regions_count = 0 +regions_sizes = [] + +for i in range(N): + for j in range(M): + if visited[i][j] == 0: + explore(i, j) + regions_count += 1 + regions_sizes.append(region_size[0]) + region_size[0] = 0 + +regions_sizes.sort() + +print(regions_count) +print(*regions_sizes) diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\352\271\200\354\204\234\354\230\201/2667\353\262\210.py" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\352\271\200\354\204\234\354\230\201/2667\353\262\210.py" new file mode 100644 index 0000000..89a1a33 --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\352\271\200\354\204\234\354\230\201/2667\353\262\210.py" @@ -0,0 +1,38 @@ +from collections import deque + +size = int(input()) +grid = [[int(x) for x in input()] for _ in range(size)] + +# 상하좌우 +dx = [0, 0, 1, -1] +dy = [1, -1, 0, 0] + +def bfs(start_x, start_y): + queue = deque() + queue.append((start_x, start_y)) + grid[start_x][start_y] = 0 + count = 1 + + while queue: + current_x, current_y = queue.popleft() + for i in range(4): + next_x = current_x + dx[i] + next_y = current_y + dy[i] + if next_x < 0 or next_x >= size or next_y < 0 or next_y >= size: + continue + if grid[next_x][next_y] == 1: + grid[next_x][next_y] = 0 + queue.append((next_x, next_y)) + count += 1 + return count + +component_sizes = [] +for i in range(size): + for j in range(size): + if grid[i][j] == 1: + component_sizes.append(bfs(i, j)) + +component_sizes.sort() +print(len(component_sizes)) +for size in component_sizes: + print(size) diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\352\271\200\354\204\234\354\230\201/README.md" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\352\271\200\354\204\234\354\230\201/README.md" new file mode 100644 index 0000000..8b13789 --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\352\271\200\354\204\234\354\230\201/README.md" @@ -0,0 +1 @@ + diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\274\352\270\260\355\231\215/18352.py" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\274\352\270\260\355\231\215/18352.py" new file mode 100644 index 0000000..7025b00 --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\274\352\270\260\355\231\215/18352.py" @@ -0,0 +1,34 @@ +import heapq +import sys +f = sys.stdin.readline +INF = int(1e9) + +n, m, k, x = map(int, f().split()) +graph = [[] for _ in range(n+1)] +distance = [INF] * (n+1) + +for _ in range(m): + a, b = map(int, f().split()) + graph[a].append((b, 1)) + +def dijkstra(start): + q = [] + heapq.heappush(q, (0, start)) + distance[start] = 0 + while q: + dist, now = heapq.heappop(q) + if distance[now] < dist: continue + for j in graph[now]: + cost = dist + j[1] + if cost < distance[j[0]]: + distance[j[0]] = cost + heapq.heappush(q, (cost, j[0])) + +dijkstra(x) +answer = [] +for i in range(1, n+1): + if distance[i] == k: answer.append(i) + +if len(answer) == 0: print(-1) +else: + for i in answer: print(i, end='\n') \ No newline at end of file diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\274\352\270\260\355\231\215/2583.py" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\274\352\270\260\355\231\215/2583.py" new file mode 100644 index 0000000..7087ca3 --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\274\352\270\260\355\231\215/2583.py" @@ -0,0 +1,42 @@ +from collections import deque + +m, n, k = map(int, input().split()) +graph = [[0] * n for _ in range(m)] + +for _ in range(k): + x1, y1, x2, y2 = map(int, input().split()) + for i in range(x1, x2): + for j in range(m-y1-1, m-y2-1, -1): + graph[j][i] = 1 + +dx = [-1, 1, 0, 0] +dy = [0, 0, 1, -1] + +def bfs(x,y): + queue = deque() + queue.append((x, y)) + graph[x][y] = 1 + size = 1 + while queue: + x, y = queue.popleft() + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + if 0 <= nx < m and 0 <= ny < n: + if graph[nx][ny] == 0: + graph[nx][ny] = 1 + queue.append((nx, ny)) + size += 1 + result.append(size) + + +result = [] +for i in range(m): + for j in range(n): + if graph[i][j] == 0: + bfs(i, j) + +result.sort() +print(len(result)) +for i in result: + print(i, end=' ') \ No newline at end of file diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\274\352\270\260\355\231\215/2667.py" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\274\352\270\260\355\231\215/2667.py" new file mode 100644 index 0000000..1b85ac8 --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\274\352\270\260\355\231\215/2667.py" @@ -0,0 +1,45 @@ +from collections import deque + +N = int(input()) +graph = [] # 미로를 저장할 리스트(visited 정보 저장) +house = [] # 각 단지내 집의 수 저장 +count = 0 # 총 단지 수 저장 + +for _ in range(N): + graph.append(list(map(int, input()))) + +dx = [1, -1, 0, 0] +dy = [0, 0, -1, 1] + +def bfs(x, y): + Q = deque() + Q.append((x, y)) + graph[x][y] = 0 # 현재 위치를 0으로 만듬 + cnt = 1 # 단지 수 + + while Q: + x, y = Q.popleft() + for _ in range(4): + nx = x + dx[_] + ny = y + dy[_] + if 0 <= nx < N and 0 <= ny < N: + if graph[nx][ny] == 1: + graph[nx][ny] = 0 + Q.append((nx, ny)) + cnt += 1 + return cnt + + +for i in range(N): + for j in range(N): + if graph[i][j] == 1: + house.append(bfs(i, j)) + count += 1 + + +# 출력 부분 +print(count) +house.sort() +for _ in range(count) : + print(house[_]) + diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\274\352\270\260\355\231\215/README.md" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\274\352\270\260\355\231\215/README.md" new file mode 100644 index 0000000..3f03d76 --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\353\257\274\352\270\260\355\231\215/README.md" @@ -0,0 +1,10 @@ +image + + +**문제 2667번 (단지 번호 붙이기)** +풀이과정: +1. NxN 미로를 처음부터 검사 +2. 지나갈 수 있는(1로 되어 있는) 부분에서 bfs +3. 지나간 부분은 0으로 만들기 +4. 단지 수 세기 + diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\204\234\353\217\231\355\230\201/18352.py" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\204\234\353\217\231\355\230\201/18352.py" new file mode 100644 index 0000000..60ccdd6 --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\204\234\353\217\231\355\230\201/18352.py" @@ -0,0 +1,39 @@ +import sys, heapq +input = sys.stdin.readline +INF = float('inf') + + +def dijkstra(start): + q = [] + heapq.heappush(q, (0, start)) + distance[start] = 0 + + while q: + dist, now = heapq.heappop(q) + if dist > distance[now]: + continue + for i in graph[now]: + cost = dist + i[1] + if cost < distance[i[0]]: + distance[i[0]] = cost + heapq.heappush(q, (cost, i[0])) + + +n, m, k, start = map(int, input().split()) +graph = [[] for _ in range(n+1)] +distance = [INF] * (n+1) + +for _ in range(m): + a, b = map(int, input().split()) + graph[a].append((b, 1)) + +dijkstra(start) + +isNone = 1 +for i in range(1, n+1): + if distance[i] == k: + isNone = 0 + print(i) + +if isNone: + print(-1) \ No newline at end of file diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\204\234\353\217\231\355\230\201/2583.py" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\204\234\353\217\231\355\230\201/2583.py" new file mode 100644 index 0000000..f4440dd --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\204\234\353\217\231\355\230\201/2583.py" @@ -0,0 +1,42 @@ +import sys +sys.setrecursionlimit(10**6) + +M, N, K = map(int, input().split()) + +graph = [] +result = [] +count = 0 +my_map = [[1]*(M) for i in range(N)] + +for i in range(K): + graph.append(list(map(int,input().split()))) +dx = [0,0,1,-1] +dy = [1,-1,0,0] + +for i in range(K): + for j in range(graph[i][0], graph[i][2]): + for k in range(graph[i][1], graph[i][3]): + my_map[j][k] = 0 + +def dfs(x,y): + global count + + if x<0 or y<0 or x>=N or y>=M: + return + if my_map[x][y] == 1: + count = count + 1 + my_map[x][y] = 0 + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + dfs(nx,ny) +for i in range(N): + for j in range(M): + if my_map[i][j] == 1: + dfs(i,j) + result.append(count) + count = 0 +result.sort() +print(len(result)) +for i in result: + print(i, end=" ") \ No newline at end of file diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\204\234\353\217\231\355\230\201/2667.py" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\204\234\353\217\231\355\230\201/2667.py" new file mode 100644 index 0000000..64f530e --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\204\234\353\217\231\355\230\201/2667.py" @@ -0,0 +1,38 @@ +from collections import deque + +N = int(input()) + +graph = [] +result = [] +count = 0 + +for i in range(N): + graph.append(list(map(int, input()))) +dx = [0,0,1,-1] +dy = [1,-1,0,0] + +def dfs(x,y): + global count + #정사각형 지도 밖으로 나갈 경우 + if x<0 or x>=N or y<0 or y>=N: + return + #방문한적이 없는 집들의 경우 + if graph[x][y] == 1: + count = count + 1 + graph[x][y] = 0 #방문처리 + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + dfs(nx,ny) + +for i in range(N): + for j in range(N): + if graph[i][j] == 1: + dfs(i,j) + result.append(count) + count = 0 + +result.sort() +print(len(result)) +for i in result: + print(i) \ No newline at end of file diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\204\234\353\217\231\355\230\201/README.md" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\204\234\353\217\231\355\230\201/README.md" new file mode 100644 index 0000000..67305d9 --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\204\234\353\217\231\355\230\201/README.md" @@ -0,0 +1 @@ +테스트 용 diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\204\234\353\217\231\355\230\201/abc.txt" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\204\234\353\217\231\355\230\201/abc.txt" new file mode 100644 index 0000000..e69de29 diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\240\225\354\232\260\355\230\204/18352.py" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\240\225\354\232\260\355\230\204/18352.py" new file mode 100644 index 0000000..b1be2cf --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\240\225\354\232\260\355\230\204/18352.py" @@ -0,0 +1,37 @@ +N,M,K,X = map(int,input().split()) +g = [[] for _ in range(N+1)] +#1번 도시 부터 있기 때문에 M+1을 해서 변수 그대로 사용한다. + +v = [[0] for _ in range(M+1)] +#방문을 확인한다. +a=[] + +for i in range(M): + x,y = map(int,input().split()) + g[x]+=[y] + #단방향이기 때문에 하나만 연결한다. + +def bfs(z): + q=[] + q.append((v,0)) + v[z] = 1 + while q: + now,n = q.pop(0) + if n == K: + a.append(now) + elif n > K: + return + for i in g[now]: + if v[i] == 0: + v[i] = 1 + q.append([i,n+1]) + + +bfs(X) +if not a: + print(-1) +else: + a.sort() + print(*a,sep = "\n") + + diff --git "a/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\240\225\354\232\260\355\230\204/2583.py" "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\240\225\354\232\260\355\230\204/2583.py" new file mode 100644 index 0000000..7b5d2ae --- /dev/null +++ "b/08\354\243\274\354\260\250 \353\257\270\353\241\234\355\203\220\354\203\211&\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\240\225\354\232\260\355\230\204/2583.py" @@ -0,0 +1,40 @@ +M,N,K = map(int,input().split()) +arr = [[1]*N for _ in range(M)] +#지정된 사각형 외의 영역을 측정하기 때문에 1로 다 채워준다. + +for i in range(K): + x,y,xx,yy = map(int,input().split()) + + for i in range(y,yy): + for j in range(x,xx): + arr[i][j] = 0 + +dx = [-1,1,0,0] +dy = [0,0,-1,1] + +a = [] +v = [[0]*N for _ in range(M)] +def bfs(x,y): + q = [] + q.append((x,y)) + v[x][y] = 1 + count = 1 + + while q: + x,y = q.pop(0) + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + if 0<=nx 이를 결과를 넣는 배열에 넣어 정렬 후 출력해준다. + +2583번 영역 구하기 +주어진 직사각형을 제외한 나머지 분리된 영역을 구하는 것이기 때문에 +M*N의 배열을 1로 채워준다. 그 다음 직사각형의 내부에 있는 x,y 좌표 값들을 +0으로 바꾸어준다. 이는 미로에서 길이 아님을 의미한다. +2667번과 비슷하게 count를 사용하여 각 영역 내에 칸의 수를 구해준다. +for 문을 이용해서 M*N 배열 안에 있는 수 중 방문을 안 했고 배열의 값이 1인 좌표를 +bfs를 돌려준다. + +18352번 특정거리의 도시 찾기 +https://ji-gwang.tistory.com/456 +못풀어서 위 자료를 이용하여 풀었다. +bfs를 사용하여 풀었으며 좌표 대신 도시의 번호와 거리를 변수로 사용하였다. +처음 입력 받은 값은 출발 도시이기 때문에 거리를 0으로 해준다. +갈 수 있는 도시를 조사하고 거리를 1 더해주고 이동한 도시에서 +다른 도시로 갈 수 있는지 조사하는 것을 반복한다. +그러다 거리인 n 값이 K와 같아 지면 결과 배열인 a에 넣어준다. n이 K를 넘어가게 되면 +더 이상 확인할 필요가 없으므로 종료한다. +배열이 비었다면 -1을 출력하고 아니면 정렬 후 출력해준다. diff --git "a/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/README.md" "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/README.md" new file mode 100644 index 0000000..cbe80a6 --- /dev/null +++ "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/README.md" @@ -0,0 +1,50 @@ +> # 스터디 회의: +> 1. 앞으로 찾은 문제는 직접 해당 주차의 readme에 작성하기 +> 2. readme 쓰는 방법은 0주차 readme의 링크로 보기(구글에 readme 고치기만 쳐도 나오긴 함) +> 3. 담주 간략하게 "치킨 배달" 백트레킹을 이용한 방법 얘기하기 +> 4. 오늘 스터디 때 풀었던 "평범한 배낭"(12865번) 9주차에 올리기 + +## 숙제 +|난이도|번호|제목|링크| +|-|-|-|-| +|실버 1|11052번|카드 구매하기|https://www.acmicpc.net/problem/11052| +|골드 5|15686번|치킨 배달|https://www.acmicpc.net/problem/15686| + +> ## 이번 스터디 핵심! +> 15686번 치킨 배달 : +> 백트래킹 vs 콤비네이션 -> 콤비네이션 내장 함수를 이용하는게 시간복잡도와 코드 복잡도 부분에서 더 이득이었다! + +## 스터디 진행 중 풀이 +|난이도|번호|제목|링크| +|-|-|-|-| +|골드 5|12865번|평범한 배낭|https://www.acmicpc.net/problem/12865| +#### -> 각자 담주까지 풀어오기 + +## 찾아온 문제들 +#### 민기홍 +|난이도|번호|제목|링크| +|-|-|-|-| +|골드 4|3190번|뱀|https://www.acmicpc.net/problem/3190| +|골드 5|15686번|치킨 배달|https://www.acmicpc.net/problem/15686| + +#### 김서영 +|난이도|번호|제목|링크| +|-|-|-|-| +|골드 1|13460번|구슬 탈출2|https://www.acmicpc.net/problem/13460| +|실버 1|2468번|안전 영역|https://www.acmicpc.net/problem/2468| +|골드 2|1513번|경로 찾기|https://www.acmicpc.net/problem/1513| +|골드 4|1043번|거짓말|https://www.acmicpc.net/problem/1043| +|실드 2|11048번|이동하기|https://www.acmicpc.net/problem/11048| + +#### 정우현 +|난이도|번호|제목|링크| +|-|-|-|-| +|골드 3|16236번|아기상어|https://www.acmicpc.net/problem/16236| +|골드 4|14226번|이모티콘|https://www.acmicpc.net/problem/14226| +|골드 3|16724번|피리부는사나이|https://www.acmicpc.net/problem/16724| + +#### 서동혁 +|난이도|번호|제목|링크| +|-----|-----|---------------------|----------------------------------------| +|골드 4|1963번|소수 경로|https://www.acmicpc.net/problem/1963| +|실버 1|1325번|효율적인 해킹|https://www.acmicpc.net/problem/1325| diff --git "a/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\352\271\200\354\204\234\354\230\201/11052 \353\262\210.py" "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\352\271\200\354\204\234\354\230\201/11052 \353\262\210.py" new file mode 100644 index 0000000..3acf5ce --- /dev/null +++ "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\352\271\200\354\204\234\354\230\201/11052 \353\262\210.py" @@ -0,0 +1,13 @@ +import sys + +num_items = int(sys.stdin.readline()) +item_prices = [0] +item_prices += list(map(int, sys.stdin.readline().split())) + +for idx in range(1, num_items + 1): + temp = [] + for t in range(idx // 2 + 1): + temp.append(item_prices[t] + item_prices[idx - t]) + item_prices[idx] = max(temp) + +sys.stdout.write(str(item_prices[num_items])) diff --git "a/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\352\271\200\354\204\234\354\230\201/15686\353\262\210.py" "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\352\271\200\354\204\234\354\230\201/15686\353\262\210.py" new file mode 100644 index 0000000..9af6e51 --- /dev/null +++ "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\352\271\200\354\204\234\354\230\201/15686\353\262\210.py" @@ -0,0 +1,60 @@ +import sys +input_reader = sys.stdin.readline + +N, M = map(int, input_reader().split()) +grid = [] +coordinates_of_2 = [] +coordinates_of_1 = [] + +for y in range(N): + line = list(map(int, input_reader().split())) + if 2 in line: + for x in range(len(line)): + if line[x] == 2: + coordinates_of_2.append((y, x)) + if 1 in line: + for x in range(len(line)): + if line[x] == 1: + coordinates_of_1.append((y, x)) + grid.append(line) + +min_distance = sys.maxsize +selected_coordinates = [] +count_of_2 = len(coordinates_of_2) + + +def remove_2(start: int): + condition = count_of_2 - len(selected_coordinates) + if M == condition: + calculate_distance(selected_coordinates) + + + for i in range(start, len(coordinates_of_2)): + (y, x) = coordinates_of_2[i] + if (y, x) not in selected_coordinates: + selected_coordinates.append((y, x)) + remove_2(i + 1) + selected_coordinates.pop() + + +def calculate_distance(selected_coordinates: list): + global min_distance + distance = {} + + for fr in coordinates_of_2: + if fr in selected_coordinates: + continue + for to in coordinates_of_1: + if to not in distance.keys(): + distance[to] = sys.maxsize + distance[to] = min(distance[to], abs(fr[0] - to[0]) + abs(fr[1] - to[1])) + + sum_of_distances = 0 + for i in distance.keys(): + sum_of_distances += distance[i] + + min_distance = min(min_distance, sum_of_distances) + + +remove_2(0) +print(min_distance) diff --git "a/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\353\257\274\352\270\260\355\231\215/11052.py" "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\353\257\274\352\270\260\355\231\215/11052.py" new file mode 100644 index 0000000..77ce5ac --- /dev/null +++ "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\353\257\274\352\270\260\355\231\215/11052.py" @@ -0,0 +1,10 @@ +N = int(input()) +P = [0] + list(map(int, input().split())) +value = [0 for _ in range(N+1)] + +for i in range(1, N+1): + for j in range(1, i+1): + value[i] = max(value[i], value[i-j] + P[j]) + +print(value[N]) + diff --git "a/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\353\257\274\352\270\260\355\231\215/12865.py" "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\353\257\274\352\270\260\355\231\215/12865.py" new file mode 100644 index 0000000..4279b7b --- /dev/null +++ "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\353\257\274\352\270\260\355\231\215/12865.py" @@ -0,0 +1,20 @@ +N, K = map(int, input().split()) +WV = [[0 for _ in range(2)] for i in range(N)] # 무게 +result = [0 for _ in range(N)] +max_result = 0 + + +for i in range(N): + WV[i][0], WV[i][1] = map(int, input().split()) +# +# WV.sort() + +# dp +for i in range(N, 0, -1): + limit = K + for j in range(i, 0, -1): + if WV[j-1][0] <= limit : + limit -= WV[j-1][0] + result[i-1] += WV[j-1][1] + +print(result) \ No newline at end of file diff --git "a/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\354\204\234\353\217\231\355\230\201/11052.py" "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\354\204\234\353\217\231\355\230\201/11052.py" new file mode 100644 index 0000000..57de3cd --- /dev/null +++ "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\354\204\234\353\217\231\355\230\201/11052.py" @@ -0,0 +1,11 @@ +N = int(input()) +value = list(map(int, input().split())) +value.insert(0,0) + +dp = value +for i in range(1, N): + for j in range(1,i+1): + if dp[i+1] <= value[j] + dp[i+1-j]: + dp[i+1] = value[j] + dp[i+1-j] + +print(dp[N]) \ No newline at end of file diff --git "a/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\354\204\234\353\217\231\355\230\201/15686.py" "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\354\204\234\353\217\231\355\230\201/15686.py" new file mode 100644 index 0000000..5f42924 --- /dev/null +++ "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\354\204\234\353\217\231\355\230\201/15686.py" @@ -0,0 +1,30 @@ +import sys +from itertools import combinations + +input = sys.stdin.readline + +n, m = map(int, input().split()) +city = list(list(map(int, input().split())) for _ in range(n)) +result = 999999 +house = [] # 집의 좌표 +chick = [] # 치킨집의 좌표 + +for i in range(n): + for j in range(n): + if city[i][j] == 1: + house.append([i, j]) + elif city[i][j] == 2: + chick.append([i, j]) + +for chi in combinations(chick, m): # m개의 치킨집 선택 + temp = 0 # 도시의 치킨 거리 + for h in house: + chi_len = 999 # 각 집마다 치킨 거리 + for j in range(m): + chi_len = min(chi_len, abs(h[0] - chi[j][0]) + abs(h[1] - chi[j][1])) + temp += chi_len + result = min(result, temp) + +print(result) + +#https://codesyun.tistory.com/185 조합을 사용한듯 어떻게 한건지 같이 봐보자 \ No newline at end of file diff --git "a/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\354\240\225\354\232\260\355\230\204/11052.py" "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\354\240\225\354\232\260\355\230\204/11052.py" new file mode 100644 index 0000000..feb1948 --- /dev/null +++ "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\354\240\225\354\232\260\355\230\204/11052.py" @@ -0,0 +1,11 @@ +N = int(input()) +a = list(map(int,input().split())) +a.insert(0,0) +dp = [0 for _ in range(N+1)] + +for i in range(1,N+1): + for j in range(1,N+1): + if j-i>=0: + dp[j] = max(dp[j],a[i]+dp[j-i]) + +print(dp[N]) diff --git "a/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\354\240\225\354\232\260\355\230\204/15686.py" "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\354\240\225\354\232\260\355\230\204/15686.py" new file mode 100644 index 0000000..9ea906b --- /dev/null +++ "b/09\354\243\274\354\260\250 \354\271\264\353\223\234\352\265\254\353\247\244\355\225\230\352\270\260&\354\271\230\355\202\250\353\260\260\353\213\254/\354\240\225\354\232\260\355\230\204/15686.py" @@ -0,0 +1,26 @@ +from itertools import combinations + +N, M = map(int, input().split()) +arr = [list(map(int, input().split())) for _ in range(N)] + +chicken = [] +home = [] +result = float('inf') # 결과값을 무한대로 초기화 초기 값을 설정하기 위해 + +for i in range(N): + for j in range(N): + if arr[i][j] == 1: + home.append((i, j)) + if arr[i][j] == 2: + chicken.append((i, j)) + +for comb in combinations(chicken, M): # 조합 생성 + temp = 0 + for j in home: + c_len = float('inf') # c_len을 무한대로 초기화 초기 값을 설정하기 위해 + for k in range(M): + c_len = min(c_len, abs(j[0] - comb[k][0]) + abs(j[1] - comb[k][1])) + temp += c_len + result = min(result, temp) + +print(result) diff --git "a/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/README.md" "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/README.md" new file mode 100644 index 0000000..3d0ae75 --- /dev/null +++ "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/README.md" @@ -0,0 +1,49 @@ +> 마크다운 사용법 링크: https://gist.github.com/ihoneymon/652be052a0727ad59601 + +> 2/7 회의 내용: +> 1. 코테 문제 선정 +> 쉬운 dp, 백트래킹 1문제씩 풀고 저번 시간(김서영 가고 난 이후)에 풀었던 "평범한 배낭"문제 마무리 +> 2. 담주 월요일(설연휴) 스터디 일정 +> **4명 모두 디코가 가능하면 디코로 진행. 1명이라도 미참여 시 깃에 풀이과정 상세히 올리는 거로 대체.** +> 예시) dp 문제면 답에 해당되는 점화식이 나오게 된 풀이과정을 꼭 제시해야 함. +> 점화식에 1이 들어갈 때, 2가 들어갈 때... +> 3. **김동주 교수의 스터디 참전 소식** +> 4. **앞으로 찾아온 문제는 해당 주차 readme에 본인이 직접 수정해서 넣기** + +## 숙제 +|난이도|번호|제목|링크| +|-|-|-|-| +|실버 3|9461번|파도반수열|https://www.acmicpc.net/problem/9461| +|실버 1|14888번|연산자 끼워넣기|https://www.acmicpc.net/problem/14888| +|골드 5|12865번|평범한 배낭|https://www.acmicpc.net/problem/12865| + +## 스터디 진행 중 풀이 +|난이도|번호|제목|링크| +|-----|-----|----------|----------------------------------------| +|난이도|번호|제목|링크| +|골드 5|9251번|LCS|https://www.acmicpc.net/problem/9251| + + +## 찾아온 문제들 +#### 민기홍 +|난이도|번호|제목|링크| +|-----|-----|---------------------|----------------------------------------| +|골드 5|2293번|동전 1|https://www.acmicpc.net/problem/2293| +|골드 5|2294번|동전 2|https://www.acmicpc.net/problem/2294| + +#### 김서영 +|난이도|번호|제목|링크| +|-----|-----|---------------------|----------------------------------------| +|골드 4|번||https://www.acmicpc.net/problem/| +|골드 5|번||https://www.acmicpc.net/problem/| + +#### 정우현 +|난이도|번호|제목|링크| +|-----|-----|---------------------|----------------------------------------| +|골드 5|15486번|퇴사 2|https://www.acmicpc.net/problem/15486| +|골드 5|9251번|LCS|https://www.acmicpc.net/problem/9251| + +#### 서동혁 +|난이도|번호|제목|링크| +|-----|-----|---------------------|----------------------------------------| +|실버 1|14888번||https://www.acmicpc.net/problem/14888| diff --git "a/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\353\257\274\352\270\260\355\231\215/12865_dedupe_ver.py" "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\353\257\274\352\270\260\355\231\215/12865_dedupe_ver.py" new file mode 100644 index 0000000..4279b7b --- /dev/null +++ "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\353\257\274\352\270\260\355\231\215/12865_dedupe_ver.py" @@ -0,0 +1,20 @@ +N, K = map(int, input().split()) +WV = [[0 for _ in range(2)] for i in range(N)] # 무게 +result = [0 for _ in range(N)] +max_result = 0 + + +for i in range(N): + WV[i][0], WV[i][1] = map(int, input().split()) +# +# WV.sort() + +# dp +for i in range(N, 0, -1): + limit = K + for j in range(i, 0, -1): + if WV[j-1][0] <= limit : + limit -= WV[j-1][0] + result[i-1] += WV[j-1][1] + +print(result) \ No newline at end of file diff --git "a/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\353\257\274\352\270\260\355\231\215/14888.py" "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\353\257\274\352\270\260\355\231\215/14888.py" new file mode 100644 index 0000000..d027d83 --- /dev/null +++ "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\353\257\274\352\270\260\355\231\215/14888.py" @@ -0,0 +1,31 @@ +N = int(input()) # 수의 개수 +A = list(map(int, input().split())) # 숫자 입력(수열) +operator = list(map(int, input().split())) # 연산자 입력 + +maximum = -1e9 # e나 E 뒤에 숫자는 10의 지수 (따라서 10의 9승인 10억) +minimum = 1e9 + +def backtrack(depth, total, plus, minus, multi, divide): + global maximum, minimum + + if depth == N: + maximum = max(total, maximum) + minimum = min(total, minimum) + return + + if plus: + backtrack(depth+1, total+A[depth], plus-1, minus, multi, divide) + if minus: + backtrack(depth + 1, total - A[depth], plus, minus-1, multi, divide) + if multi: + backtrack(depth + 1, total * A[depth], plus, minus, multi-1, divide) + if divide: + if total < 0: + backtrack(depth + 1, -(-total // A[depth]), plus, minus, multi, divide - 1) + else: + backtrack(depth + 1, total // A[depth], plus, minus, multi, divide - 1) + +backtrack(1, A[0], operator[0], operator[1], operator[2], operator[3]) +print(maximum) +print(minimum) + diff --git "a/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\353\257\274\352\270\260\355\231\215/9461.py" "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\353\257\274\352\270\260\355\231\215/9461.py" new file mode 100644 index 0000000..5c611f4 --- /dev/null +++ "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\353\257\274\352\270\260\355\231\215/9461.py" @@ -0,0 +1,24 @@ +import sys +input = sys.stdin.readline + +T = int(input()) # 테스트 케이스 +case_index = [] # P(N)의 N을 담을 리스트 +P = [0, 1, 1, 1] # 파도반 수열 P +#차례로 P(0), 1, 2, 3 + +# 각 테스트 케이스 N 입력 +for t in range(T) : + case_index.append(int(input())) + + +# dynamic programing +for t in range(T): + if case_index[t] < 4: # P(1)~P(3) 값이 1 + print(1) + continue + elif len(P) >= case_index[t] and P[case_index[t]] != 1: # P(N)의 값이 리스트에 존재하면 출력 + print(P[case_index[t]]) + continue + for N in range(4, max(case_index)+1): # 입력된 N 중에 최대값부터 점화식 이용 + P.append(P[N-2] + P[N-3]) + print(P[case_index[t]]) \ No newline at end of file diff --git "a/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\353\257\274\352\270\260\355\231\215/README.md" "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\353\257\274\352\270\260\355\231\215/README.md" new file mode 100644 index 0000000..e95f28f --- /dev/null +++ "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\353\257\274\352\270\260\355\231\215/README.md" @@ -0,0 +1,48 @@ +## 파도반 수열 (9461 실버3) + +아이디어: +1. 명확한 규칙성을 보이기에 점화식을 세울 수 있어 dp 알고리즘으로 풀 수 있다. +2. 입력된 testcase에 대해 가장 높은 숫자에 대해 파도반 수열 P를 구해놓으면 그보다 작은 N에 대해서는 반복적으로 점화식을 쓸 필요없이 리스트 P에 저장된 P(N)을 출력하면 된다. + +풀이: + +**아이디어1** + +>P(1) = 1 P(2) = 1 P(3) = 1 P(4) = 2 P(5) = 2
+>P(6) = 3 P(7) = 4 P(8) = 5 P(9) = 7 P(10) = 9
+>... +> +>p(4) = P(1) + P(2) -> 2 = 1 + 1
+>P(5) = P(2) + P(3) -> 2 = 1 + 1
+>P(6) = P(3) + P(4) -> 3 = 1 + 2
+>P(7) = P(4) + P(5) -> 4 = 2 + 2
+>P(8) = P(5) + P(6) -> 5 = 2 + 3
+>P(9) = P(6) + P(7) -> 7 = 3 + 4
+>P(10) = P(7) + P(8)-> 9 = 4 + 5
+>점화식 => P(N) = P(N-3) + P(N-2) + +**아이디어2** + +>예제) testcase = 2
+>케이스1 = 6
+>케이스2 = 12
+>-> 이미 구해놓은 P(3) 이후부터 P(12)까지 점화식을 이용해 순차적으로 구한 후 남은 케이스인 P(6)은 점화식을 이용하지 않고 파도반 수열 리스트인 P에서 값을 가져와 출력 + +

+## 연산자 끼워넣기 (14888 실버1) + +아이디어: +1. 모든 경우를 구해서 최대와 최소값을 구해야 하기에 dfs을 이용한다. + +**아이디어1** + +연산자에 대해 +, -, *, //를 모두 한 번씩 먼저 수행해봐야 하기에 if문을 여러개 써서 dfs 함수에 대한 재귀호출을 진행한다.
+if plus:
+ dfs()
+if minus:
+ dfs()
+if multiple:
+ dfs()
+if divide:
+ dfs()
+-> 이런식으로 진행하면 모든 연산자를 수행 가능! diff --git "a/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\204\234\353\217\231\355\230\201/12865.py" "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\204\234\353\217\231\355\230\201/12865.py" new file mode 100644 index 0000000..6cd4008 --- /dev/null +++ "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\204\234\353\217\231\355\230\201/12865.py" @@ -0,0 +1,19 @@ +n, k = map(int, input().split()) + +thing = [[0,0]] +d = [[0]*(k+1) for _ in range(n+1)] + +for i in range(n): + thing.append(list(map(int, input().split()))) + +for i in range(1, n+1): + for j in range(1, k+1): + w = thing[i][0] + v = thing[i][1] + + if j < w: + d[i][j] = d[i-1][j] + else: + d[i][j] = max(d[i-1][j], d[i-1][j-w]+v) + +print(d[n][k]) \ No newline at end of file diff --git "a/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\204\234\353\217\231\355\230\201/14888.py" "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\204\234\353\217\231\355\230\201/14888.py" new file mode 100644 index 0000000..3b19282 --- /dev/null +++ "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\204\234\353\217\231\355\230\201/14888.py" @@ -0,0 +1,31 @@ +import sys + +input = sys.stdin.readline +N = int(input()) +num = list(map(int, input().split())) +op = list(map(int, input().split())) + +maximum = -1e9 +minimum = 1e9 + + +def dfs(depth, total, plus, minus, multiply, divide): + global maximum, minimum + if depth == N: + maximum = max(total, maximum) + minimum = min(total, minimum) + return + + if plus: + dfs(depth + 1, total + num[depth], plus - 1, minus, multiply, divide) + if minus: + dfs(depth + 1, total - num[depth], plus, minus - 1, multiply, divide) + if multiply: + dfs(depth + 1, total * num[depth], plus, minus, multiply - 1, divide) + if divide: + dfs(depth + 1, int(total / num[depth]), plus, minus, multiply, divide - 1) + + +dfs(1, num[0], op[0], op[1], op[2], op[3]) +print(maximum) +print(minimum) \ No newline at end of file diff --git "a/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\204\234\353\217\231\355\230\201/9461.py" "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\204\234\353\217\231\355\230\201/9461.py" new file mode 100644 index 0000000..b4ebf35 --- /dev/null +++ "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\204\234\353\217\231\355\230\201/9461.py" @@ -0,0 +1,18 @@ +T = int(input()) +triangle = [] +temp = [0,1,1,1,2,2] +Max = 0 +for i in range(T): + triangle.append(int(input())) + if triangle[i] > Max: + Max = triangle[i] + +if Max <= 5: + for i in range(T): + print(temp[triangle[i]]) +else: + for i in range(1,Max - 4): + temp.append(temp[i] + temp[i+4]) + +for i in range(T): + print(temp[triangle[i]]) \ No newline at end of file diff --git "a/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\240\225\354\232\260\355\230\204/12865_3.py" "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\240\225\354\232\260\355\230\204/12865_3.py" new file mode 100644 index 0000000..445e2c7 --- /dev/null +++ "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\240\225\354\232\260\355\230\204/12865_3.py" @@ -0,0 +1,26 @@ +import sys + +N, K = map(int, input().split()) +stuff = [[0,0]] +knapsack = [[0 for _ in range(K + 1)] for _ in range(N + 1)] + +for _ in range(N): + stuff.append(list(map(int, input().split()))) + + +#냅색 문제 풀이 +for i in range(1, N + 1): + for j in range(1, K + 1): + weight = stuff[i][0] + value = stuff[i][1] + + if j < weight: + knapsack[i][j] = knapsack[i - 1][j] + #weight보다 작으면 위의 값을 그대로 가져온다 + else: + #그게 아니면 현재 물건의 가치 더하기 넣을 수 있는 무게에서 현재 무게를 + #뺀 값 중 최대값의 가치를 더한 것과 이전에 그 무게 넣었던 가치 중 더 큰 값을 + #넣어준다. + knapsack[i][j] = max(value + knapsack[i - 1][j - weight], knapsack[i - 1][j]) + +print(knapsack[N][K]) diff --git "a/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\240\225\354\232\260\355\230\204/14888.py" "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\240\225\354\232\260\355\230\204/14888.py" new file mode 100644 index 0000000..b8a0819 --- /dev/null +++ "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\240\225\354\232\260\355\230\204/14888.py" @@ -0,0 +1,28 @@ +n = int(input()) +num = list(map(int, input().split())) +op = list(map(int, input().split())) + +maxi = -1e9 +mini = 1e9 + +def dfs(depth, total, plus, minus, multi, divine): + global maxi, mini + if depth == n: + maxi = max(total, maxi) + mini = min(total, mini) + return + + if plus: + dfs(depth + 1, total + num[depth], plus - 1, minus, multi, divine) + if minus: + dfs(depth + 1, total - num[depth], plus, minus - 1, multi, divine) + if multi: + dfs(depth + 1, total * num[depth], plus, minus, multi - 1, divine) + if divine: + dfs(depth + 1, int(total / num[depth]), plus, minus, multi, divine - 1) + +dfs(1, num[0], op[0], op[1], op[2], op[3]) + +print(maxi) +print(mini) + diff --git "a/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\240\225\354\232\260\355\230\204/9461.py" "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\240\225\354\232\260\355\230\204/9461.py" new file mode 100644 index 0000000..297b791 --- /dev/null +++ "b/10\354\243\274\354\260\250 dp&\353\260\261\355\212\270\353\236\230\355\202\271/\354\240\225\354\232\260\355\230\204/9461.py" @@ -0,0 +1,14 @@ +T = int(input()) +arr = [0]*101 +arr[1]=1 +arr[2]=1 +arr[3]=1 + +for j in range(4, 101): + arr[j] = arr[j-2]+arr[j-3] + +for i in range(T): + n = int(input()) + print(arr[n]) + + diff --git a/README.md b/README.md index 202b5f8..4b21500 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,51 @@ # AlgorithmClass 알고리즘 스터디 깃허브 레포 + +## 코테 스터디 계획: + +- 교재: + + 이것이 코딩테스트다. (파이썬, JAVA 등 언어별로 존재) + +- 주언어: + + 통일 (Python) + +- 문제: + + 백준(문제 수는 매주 다를 수 있음) + +- 오프라인 진행 +- 모집 대상: + + 2학년 이상 (선행: 언어 1개이상,자료구조) + +- 모집인원: + + 최소 4~5명 + +- 시작 날짜: + + 2023년 10월 + +- 주차별난이도상승: + + → 시험 1주 전에 일시중단, 방학 시즌에 문제 수 증가 + + - 중, 하 (시간복잡도 계산) - 3주간 진행 예정 + - 중(시간복잡도 계산), 하 - 3주간 진행 예정 + - 중(시간복잡도 계산), 상 - 4주간 진행 예정 + - 중, 상(시간복잡도 계산) - 3~4주간 진행 예정 +- 문제풀이 방식: + 1. 에디터를 이용한 풀이 (난이도 하) + 2. 백준 or 프로그래머스의 에디터 이용 + 3. 메모장 작성 + **4. 개인 자유에 맡기기**(채택됨) +- 기간: + + 2월 까지 (13~14주) *현재 연장진행중...* + + [알고리즘 스터디](https://www.notion.so/312eedf08fa14f2eb0d0f54192e3b9a0?pvs=21) + +자세한 건 노션 0주차 회의록 확인: +https://www.notion.so/85f8430a2caa43b0af202f0fad855e95?v=e3196da9bb6e45bb9b74870fc33ee71f&p=079c0732427a4188a7a2246274ede0c6&pm=s