diff --git "a/2021_FEB/boj_1034_\353\236\250\355\224\204.py" "b/2021_2_FEB/boj_1034_\353\236\250\355\224\204.py" similarity index 100% rename from "2021_FEB/boj_1034_\353\236\250\355\224\204.py" rename to "2021_2_FEB/boj_1034_\353\236\250\355\224\204.py" diff --git "a/2021_FEB/boj_10830_\355\226\211\353\240\254\354\240\234\352\263\261.py" "b/2021_2_FEB/boj_10830_\355\226\211\353\240\254\354\240\234\352\263\261.py" similarity index 100% rename from "2021_FEB/boj_10830_\355\226\211\353\240\254\354\240\234\352\263\261.py" rename to "2021_2_FEB/boj_10830_\355\226\211\353\240\254\354\240\234\352\263\261.py" diff --git "a/2021_FEB/boj_1167_\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204.py" "b/2021_2_FEB/boj_1167_\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204.py" similarity index 100% rename from "2021_FEB/boj_1167_\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204.py" rename to "2021_2_FEB/boj_1167_\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204.py" diff --git a/2021_FEB/boj_12100_2048.py b/2021_2_FEB/boj_12100_2048.py similarity index 100% rename from 2021_FEB/boj_12100_2048.py rename to 2021_2_FEB/boj_12100_2048.py diff --git "a/2021_FEB/boj_13334_\354\262\240\353\241\234.py" "b/2021_2_FEB/boj_13334_\354\262\240\353\241\234.py" similarity index 100% rename from "2021_FEB/boj_13334_\354\262\240\353\241\234.py" rename to "2021_2_FEB/boj_13334_\354\262\240\353\241\234.py" diff --git "a/2021_FEB/boj_1662_\354\225\225\354\266\225.py" "b/2021_2_FEB/boj_1662_\354\225\225\354\266\225.py" similarity index 100% rename from "2021_FEB/boj_1662_\354\225\225\354\266\225.py" rename to "2021_2_FEB/boj_1662_\354\225\225\354\266\225.py" diff --git "a/2021_FEB/boj_2096_\353\202\264\353\240\244\352\260\200\352\270\260.py" "b/2021_2_FEB/boj_2096_\353\202\264\353\240\244\352\260\200\352\270\260.py" similarity index 100% rename from "2021_FEB/boj_2096_\353\202\264\353\240\244\352\260\200\352\270\260.py" rename to "2021_2_FEB/boj_2096_\353\202\264\353\240\244\352\260\200\352\270\260.py" diff --git "a/2021_FEB/boj_2170_\354\204\240\352\270\213\352\270\260.py" "b/2021_2_FEB/boj_2170_\354\204\240\352\270\213\352\270\260.py" similarity index 100% rename from "2021_FEB/boj_2170_\354\204\240\352\270\213\352\270\260.py" rename to "2021_2_FEB/boj_2170_\354\204\240\352\270\213\352\270\260.py" diff --git "a/2021_FEB/boj_2482_\354\203\211\354\203\201\355\231\230.py" "b/2021_2_FEB/boj_2482_\354\203\211\354\203\201\355\231\230.py" similarity index 100% rename from "2021_FEB/boj_2482_\354\203\211\354\203\201\355\231\230.py" rename to "2021_2_FEB/boj_2482_\354\203\211\354\203\201\355\231\230.py" diff --git "a/2021_FEB/boj_2668_\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.py" "b/2021_2_FEB/boj_2668_\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.py" similarity index 100% rename from "2021_FEB/boj_2668_\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.py" rename to "2021_2_FEB/boj_2668_\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.py" diff --git "a/2021_FEB/boj_9177_\353\213\250\354\226\264\354\204\236\352\270\260.py" "b/2021_2_FEB/boj_9177_\353\213\250\354\226\264\354\204\236\352\270\260.py" similarity index 100% rename from "2021_FEB/boj_9177_\353\213\250\354\226\264\354\204\236\352\270\260.py" rename to "2021_2_FEB/boj_9177_\353\213\250\354\226\264\354\204\236\352\270\260.py" diff --git a/2021_FEB/boj_9251_LCS.py b/2021_2_FEB/boj_9251_LCS.py similarity index 100% rename from 2021_FEB/boj_9251_LCS.py rename to 2021_2_FEB/boj_9251_LCS.py diff --git "a/2021_3_MAR/boj_12907_\353\217\231\353\254\274\354\233\220.py" "b/2021_3_MAR/boj_12907_\353\217\231\353\254\274\354\233\220.py" new file mode 100644 index 0000000..a6b0da0 --- /dev/null +++ "b/2021_3_MAR/boj_12907_\353\217\231\353\254\274\354\233\220.py" @@ -0,0 +1,59 @@ +# 1번부터 N번 번호매겨진 동물 + # 토끼 or 고양이 + # 키는 모두 다르다 +# 같은 동물 중 자신보다 키가 큰 동물의 수를 물을 때 +# 각 대답을 어떤 동물이 했는지 알아내려 함 + +# 출력: 가능한 조합의 수 + +# 체크할 조건 +# 1 <= N <= 40 (동물의 수) +# 0 <= 대답 <= 40 + # 각 대답은 동물의 수보다 많을 수도 있고 0일 수도 있다. + +# 대답 숫자가 적을수록 키가 크다. +# 0은 2개까지만 가능하다. + # 모든 수는 2개 초과해서 나올 수 없다. (토끼, 고양이 두 종류) +# 키가 모두 다르므로 0, 1, 2, 3... 순서로 와야한다. +# 0, 0, 1, 1 ... 짝 맞는 만큼 2의 n제곱 해서 개수를 구한다. + # 짝이 딱 떨어지는 경우 n제곱, 이외엔 n+1제곱 + # (0, 0, 1, 1, 2, 2의 경우의 수 == 0, 0, 1, 1, 2) + # 짝 맞은 후에는 가능한 경우여야 한다. + # 0, 0, 1, 1, 2, 3, 4, 5 (O) + # 0, 0, 1, 1, 2, 3, 4, 6 (X) + +def impossible(): + print(0) + exit() + +def solution(N, answers): + answers.sort() + check = [0] * 41 + for answer in answers: + check[answer] += 1 + if check[answer] > 2: impossible() + + power = 0 + for i in range(len(check)): + if check[i] == 2: + power += 1 + else: + break + if check[i]: + while i < len(check): + if check[i] == 1: i += 1 + elif check[i] == 2: impossible() + else: break + else: + i += 1 + for j in range(i, len(check)): + if check[j]: impossible() + print(2**power) + return + + for j in range(i, len(check)): + if check[j]: impossible() + print(2 ** (power + 1)) + +if __name__ == '__main__': + solution(int(input()), list(map(int, input().split()))) \ No newline at end of file diff --git "a/2021_3_MAR/boj_13458_\354\213\234\355\227\230\352\260\220\353\217\205.py" "b/2021_3_MAR/boj_13458_\354\213\234\355\227\230\352\260\220\353\217\205.py" new file mode 100644 index 0000000..234b84e --- /dev/null +++ "b/2021_3_MAR/boj_13458_\354\213\234\355\227\230\352\260\220\353\217\205.py" @@ -0,0 +1,31 @@ +# N개 시험장, i번 시험장 응시자수 Ai +# 총감독관 부감독관 각각 B명, C명 감시 가능 +# 총감독관은 1명, 부감독관은 여러명 가능 +# 응시생 모두 감시할 때 필요한 최소 감독관 수 + +# 출력: 필요한 감독관의 최소 수 + +# 체크할 조건 +# 1 <= N <= 1000000 (시험장 개수) +# 1 <= Ai <= 1000000 (응시자 수) +# 1 <= B,C <= 1000000 +# 예제를 보니 부감독관이 없어도 되는듯. + +# 시험장마다 총감독관 하나 배치하고 +# 남은 응시생 수를 커버할 수 있는 부감독관 수를 찾는다. + +def solution(N, A, B, C): + cnt = 0 + for num in A: + num -= B + cnt += 1 + if num > 0: + if num % C: cnt += 1 + cnt += num // C + print(cnt) + +if __name__ == '__main__': + N = int(input()) + A = list(map(int, input().split())) + B, C = map(int, input().split()) + solution(N, A, B, C) \ No newline at end of file diff --git "a/2021_3_MAR/programmers_42839_\354\206\214\354\210\230\354\260\276\352\270\260.py" "b/2021_3_MAR/programmers_42839_\354\206\214\354\210\230\354\260\276\352\270\260.py" new file mode 100644 index 0000000..c92a3f3 --- /dev/null +++ "b/2021_3_MAR/programmers_42839_\354\206\214\354\210\230\354\260\276\352\270\260.py" @@ -0,0 +1,34 @@ +# 한자리 숫자가 적힌 종이 조각 + # '013' == 0, 1, 3 + +# 출력: 종이 조각으로 만들 수 있는 소수 개수 + +# 체크할 조건 +# 1 <= len(numbers) <= 7 + +# 소수 판별 함수를 만든 후 완전탐색 + +from itertools import permutations + +def is_prime(number): + if number <= 1: return False + i = 2 + while i * i <= number: + if not number % i: + return False + i += 1 + return True + +def solution(numbers): + nums = set() + for i in range(1, len(numbers)+1): + for item in permutations(numbers, i): + num = int(''.join(item)) + nums.add(num) + + answer = 0 + for num in nums: + if is_prime(num): + answer += 1 + + return answer \ No newline at end of file diff --git "a/2021_4_APR/programmers_49189_\352\260\200\354\236\245\353\250\274\353\205\270\353\223\234.py" "b/2021_4_APR/programmers_49189_\352\260\200\354\236\245\353\250\274\353\205\270\353\223\234.py" new file mode 100644 index 0000000..2fdd9b8 --- /dev/null +++ "b/2021_4_APR/programmers_49189_\352\260\200\354\236\245\353\250\274\353\205\270\353\223\234.py" @@ -0,0 +1,42 @@ +# 가장 멀리 떨어진 노드: + # 최단 경로로 이동했을 때 간선의 개수가 가장 많은 노드 + +# 출력: 1번 노드에서 가장 멀리 떨어진 노드 개수 + +# 체크할 조건 + # 양방향 그래프 + # 2 <= n <= 20000 (노드의 개수) + +# 가중치가 없으므로 BFS한 가장 마지막 노드들의 개수를 출력 + +from collections import deque + +def BFS(graph, n): + q = deque([1]) + visited = [0] * (n+1) + visited[1] = 1 + while q: + cnt = len(q) + for _ in range(len(q)): + node = q.popleft() + if node in graph: + for v in graph.get(node): + if not visited[v]: + visited[v] = 1 + q.append(v) + return cnt + +def solution(n, edge): + graph = dict() + for s, e in edge: + if s in graph: + graph[s].append(e) + else: + graph[s] = [e] + if e in graph: + graph[e].append(s) + else: + graph[e] = [s] + + answer = BFS(graph, n) + return answer \ No newline at end of file diff --git "a/2021_4_APR/programmers_60057_\353\254\270\354\236\220\354\227\264\354\225\225\354\266\225.py" "b/2021_4_APR/programmers_60057_\353\254\270\354\236\220\354\227\264\354\225\225\354\266\225.py" new file mode 100644 index 0000000..d11f9a6 --- /dev/null +++ "b/2021_4_APR/programmers_60057_\353\254\270\354\236\220\354\227\264\354\225\225\354\266\225.py" @@ -0,0 +1,29 @@ +# 1개 이상의 단위로 잘라서 압축 + +# 출력: 압축한 문자열 중 가장 짧은 것의 길이 + +# 체크할 조건 +# 문자열은 제일 앞에서 정해진 길이 만큼 잘라야 함. +# 앞에서부터 잘라서 순서대로 리스트에 넣는다 [문자열, 개수] +# 모두 리스트에 넣은 후 압축된 문자열의 길이를 구하여 갱신한다. + +def solution(s): + answer = len(s) + for i in range(1, len(s)): + cnt = 0 + temp = [] + temp.append([s[:i], 1]) + j = i + while j < len(s): + string = s[j:j+i] + if temp[-1][0] == string: + temp[-1][1] += 1 + else: + temp.append([string, 1]) + j += i + for word, num in temp: + cnt += len(word) + if num > 1: + cnt += len(str(num)) + answer = min(answer, cnt) + return answer \ No newline at end of file