diff --git "a/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\352\263\265\354\234\240\352\270\260 \354\204\244\354\271\230/yoonhyeong.py" "b/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\352\263\265\354\234\240\352\270\260 \354\204\244\354\271\230/yoonhyeong.py" new file mode 100644 index 00000000..c994ce4a --- /dev/null +++ "b/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\352\263\265\354\234\240\352\270\260 \354\204\244\354\271\230/yoonhyeong.py" @@ -0,0 +1,31 @@ +import sys + +N, C = map(int, sys.stdin.readline().split()) +X = [int(sys.stdin.readline()) for _ in range(N)] + +X = sorted(X) + +start = 1 +end = X[-1] - X[0] + +result = 0 + + +while start <= end: + mid = (start + end) // 2 + + house = X[0] + count = 1 + + for i in range(1, N): + if X[i] - house >= mid: + count += 1 + house = X[i] + + if count >= C: # 공유기 다 설치 가능할 때, 갯수 갱신 후에 거리 늘림 + start = mid + 1 + result = max(mid, result) + else: # 공유기 다 설치 못할 때, 거리 좁힘 + end = mid - 1 + +print(result) \ No newline at end of file diff --git "a/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\354\271\230\355\202\250 \353\260\260\353\213\254/yoonhyeong.py" "b/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\354\271\230\355\202\250 \353\260\260\353\213\254/yoonhyeong.py" new file mode 100644 index 00000000..e82d7038 --- /dev/null +++ "b/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\354\271\230\355\202\250 \353\260\260\353\213\254/yoonhyeong.py" @@ -0,0 +1,27 @@ +import sys +from itertools import combinations + +N, M = map(int, input().split()) + +house, chicken = [], [] + +for i in range(N): + arr = list(map(int, sys.stdin.readline().split())) + for j in range(N): + if arr[j] == 1: + house.append((i, j)) + elif arr[j] == 2: + chicken.append((i, j)) + +result = 1e9 + +for c in combinations(chicken, M): # M개의 치킨집 조합 + temp = 0 + for h in house: + dis = 1e9 + for j in range(M): + dis = min(dis, abs(h[0] - c[j][0]) + abs(h[1] - c[j][1])) + temp += dis + result = min(result, temp) + +print(result)