> 알고리즘 문제 풀이/BOJ51 1568-새 (python) k = 1 result = 0 n = int(input()) while n > 0: if n - k >= 0: n = n - k k += 1 result += 1 else: k = 1 print(result) 2020. 10. 13. 11004-K번째 수 (python) """ 1. sorted 활용 """ n, k = input().split() array = map(int, input().split(' ')) array = sorted(array) print(array[int(k)-1]) """ 2. merge sort 활용 """ def merge_sort(array): if len(array) 2020. 10. 12. 2751-수 정렬하기 2 (python) """ 1. 내가 작성한 코드 (계수 정렬 알고리즘 사용) """ """ 이점: 메모리를 적게 사용함 """ import sys n = int(sys.stdin.readline()) MAX = 1_000_000 negatives = [0 for _ in range(MAX + 1)] positives = [0 for _ in range(MAX + 1)] for _ in range(n): number = int(sys.stdin.readline()) if number >= 0: positives[number] += 1 else: negatives[-number] += 1 for x in range(MAX, -1, -1): if negatives[x] >= 1: print(-x) for x in range(M.. 2020. 10. 12. 4195-친구 네트워크 (python) def find(x): if x != parents[x]: parents[x] = find(parents[x]) return parents[x] def union(x, y): root1 = find(x) root2 = find(y) if root1 != root2: parents[root2] = root1 numbers[root1] += numbers[root2] tc = int(input()) for _ in range(tc): parents = dict() numbers = dict() f = int(input()) for _ in range(f): x, y = input().split() if x not in parents: parents[x] = x numbers[x] = 1 if y not in.. 2020. 10. 12. 이전 1 ··· 6 7 8 9 10 11 12 13 다음