diff --git a/kihong/week8/BOJ10867.py b/kihong/week8/BOJ10867.py new file mode 100644 index 0000000..94352d9 --- /dev/null +++ b/kihong/week8/BOJ10867.py @@ -0,0 +1,28 @@ +"""백준 10867 중복 빼고 정렬하기""" + + +def solve(_list: list, n): + set_list = set(_list) + return sorted(set_list) + + +def main(): + import sys + + test_case = 1 + sys.stdin = open("kihong/week8/BOJ10867.txt", "r") + + for i in range(1, test_case + 1): + n = int(input()) + order = list(map(int, input().split())) + result = solve(order, n) + expect = list(map(int, input().split())) + + assert result == expect, ( + f"[{i}] 실패: " f"expected={expect}, actual_result={result}" + ) + print(f"test [{i}] 성공") + + +if __name__ == "__main__": + main() diff --git a/kihong/week8/BOJ10867.txt b/kihong/week8/BOJ10867.txt new file mode 100644 index 0000000..de071db --- /dev/null +++ b/kihong/week8/BOJ10867.txt @@ -0,0 +1,3 @@ +10 +1 4 2 3 1 4 2 3 1 2 +1 2 3 4 \ No newline at end of file diff --git a/kihong/week8/BOJ1449.py b/kihong/week8/BOJ1449.py new file mode 100644 index 0000000..9353658 --- /dev/null +++ b/kihong/week8/BOJ1449.py @@ -0,0 +1,42 @@ +"""백준 1449 수리공 실버""" + + +def solve(_list: list, k): + board = [True] * 1001 # 배수관의 위치 배열 + + _list.sort() + + cnt = 0 # 테이프 갯수 + + for i in _list: + board[i] = False # 배수관이 뚫긴 곳 기록 + + for i in _list: + if not board[i]: # 만약 뚫렸다면 + for idx in range(k): + if (i + idx) < 1001: + board[i + idx] = True + cnt += 1 + return cnt + + +def main(): + import sys + + test_case = 3 + sys.stdin = open("kihong/week8/BOJ1449.txt", "r") + + for i in range(1, test_case + 1): + n, k = map(int, input().split()) + order = list(map(int, input().split())) + result = solve(order, k) + print(result) + expect = int(input()) + assert result == expect, ( + f"[{i}] 실패: " f"expected={expect}, actual_result={result}" + ) + print(f"test [{i}] 성공") + + +if __name__ == "__main__": + main() diff --git a/kihong/week8/BOJ1449.txt b/kihong/week8/BOJ1449.txt new file mode 100644 index 0000000..060ae7a --- /dev/null +++ b/kihong/week8/BOJ1449.txt @@ -0,0 +1,9 @@ +4 2 +1 2 100 101 +2 +4 3 +1 2 3 4 +2 +3 1 +3 2 1 +3 \ No newline at end of file diff --git a/kihong/week8/BOJ18110.py b/kihong/week8/BOJ18110.py new file mode 100644 index 0000000..26f981f --- /dev/null +++ b/kihong/week8/BOJ18110.py @@ -0,0 +1,47 @@ +"""백준 18110 solved.ac +python 반올림 이슈가 있었음. round 함수는 짝수에 대해서 내림 결과가 다름. +heapq를 사용하려고 했으나, 구조적인 문제로 사용할 수가 없었음. 오히려 비 효율적인 문제라서. +""" + +import math + + +def solve(_list: list, n): + def round_half(n: int): + return math.floor(n + 0.5) + + _list.sort() + + if n == 0: + return 0 + + start = round_half(n * 0.15) + + end = n - start + cnt = n - (start * 2) + + mean_value = round_half(sum(_list[start:end]) / cnt) + return mean_value + + +def main(): + import sys + + test_case = 3 + sys.stdin = open("kihong/week8/BOJ18110.txt", "r") + + for i in range(1, test_case + 1): + n = int(input()) + listed = [] + for _ in range(n): + listed.append(int(input())) + result = solve(listed, n) + expect = int(input()) + assert result == expect, ( + f"[{i}] 실패: " f"expected={expect}, actual_result={result}" + ) + print(f"test [{i}] 성공") + + +if __name__ == "__main__": + main() diff --git a/kihong/week8/BOJ18110.txt b/kihong/week8/BOJ18110.txt new file mode 100644 index 0000000..5424422 --- /dev/null +++ b/kihong/week8/BOJ18110.txt @@ -0,0 +1,23 @@ +5 +1 +5 +5 +7 +8 +6 +10 +1 +13 +12 +15 +3 +16 +13 +12 +14 +15 +13 +2 +15 +10 +13 diff --git a/kihong/week8/BOJ2170.py b/kihong/week8/BOJ2170.py new file mode 100644 index 0000000..7face6d --- /dev/null +++ b/kihong/week8/BOJ2170.py @@ -0,0 +1,49 @@ +"""백준 2170 선 긋기""" + + +def solve(lines: list, n: int): + lines.sort() + results = [] + start = lines[0][0] + end = lines[0][1] + for x, y in lines[1:]: + if start <= x and x <= end: + if end < y: + end = y + elif start <= y and y <= end: + if start > x: + start = x + elif start > x and y > end: + end = y + start = x + else: + results.append(abs(end - start)) + start = x + end = y + results.append(abs(end - start)) + return sum(results) + + +def main(): + import sys + + test_case = 1 + sys.stdin = open("kihong/week8/BOJ2170.txt", "r") + + for i in range(1, test_case + 1): + n = int(input()) + lines = [] + for _ in range(n): + x, y = map(int, input().split()) + lines.append([x, y]) + result = solve(lines, n) + print(result) + expect = int(input()) + assert result == expect, ( + f"[{i}] 실패: " f"expected={expect}, actual_result={result}" + ) + print(f"test [{i}] 성공") + + +if __name__ == "__main__": + main() diff --git a/kihong/week8/BOJ2170.txt b/kihong/week8/BOJ2170.txt new file mode 100644 index 0000000..86f648f --- /dev/null +++ b/kihong/week8/BOJ2170.txt @@ -0,0 +1,6 @@ +4 +1 3 +2 5 +3 5 +6 7 +5 \ No newline at end of file diff --git a/kihong/week8/BOJ2212.py b/kihong/week8/BOJ2212.py new file mode 100644 index 0000000..ef5e083 --- /dev/null +++ b/kihong/week8/BOJ2212.py @@ -0,0 +1,41 @@ +"""백준 2212 센서""" + + +def solve(_list: list, n, k): + # k가 n보다 크거나 같으면, 모든 센서를 각각 1개의 집중국으로 커버 가능. + if k >= n: + return 0 + + _list.sort() + # 인접한 센서 간의 거리를 계산하여, 각 간격이 최소화하게 함. + gaps = [] + for i in range(1, n): + gap = _list[i] - _list[i - 1] + gaps.append(gap) + + gaps.sort(reverse=True) + + return sum(gaps[k - 1 :]) + + +def main(): + import sys + + test_case = 2 + sys.stdin = open("kihong/week8/BOJ2212.txt", "r") + + for i in range(1, test_case + 1): + n = int(input()) + k = int(input()) + order = list(map(int, input().split())) + result = solve(order, n, k) + print(result) + expect = int(input()) + assert result == expect, ( + f"[{i}] 실패: " f"expected={expect}, actual_result={result}" + ) + print(f"test [{i}] 성공") + + +if __name__ == "__main__": + main() diff --git a/kihong/week8/BOJ2212.txt b/kihong/week8/BOJ2212.txt new file mode 100644 index 0000000..8415945 --- /dev/null +++ b/kihong/week8/BOJ2212.txt @@ -0,0 +1,8 @@ +6 +2 +1 6 9 3 6 7 +5 +10 +5 +20 3 14 6 7 8 18 10 12 15 +7 \ No newline at end of file diff --git a/kihong/week8/README.md b/kihong/week8/README.md index 8009e83..01c6b69 100644 --- a/kihong/week8/README.md +++ b/kihong/week8/README.md @@ -1,2 +1 @@ # Week 8 -Created on 2025-10-05