diff --git "a/AejiJeon/programmers/210425sprint/\354\241\260\354\235\264\354\212\244\355\213\261.py" "b/AejiJeon/programmers/210425sprint/\354\241\260\354\235\264\354\212\244\355\213\261.py" new file mode 100644 index 0000000..e69de29 diff --git "a/AejiJeon/programmers/210502sprint/\353\215\224\353\247\265\352\262\214.py" "b/AejiJeon/programmers/210502sprint/\353\215\224\353\247\265\352\262\214.py" new file mode 100644 index 0000000..5b79a12 --- /dev/null +++ "b/AejiJeon/programmers/210502sprint/\353\215\224\353\247\265\352\262\214.py" @@ -0,0 +1,23 @@ +import heapq + + +def solution(scoville, K): + + count = 0 + heapq.heapify(scoville) + while scoville: + + min1 = heapq.heappop(scoville) + # 모든 음식의 스코빌 지수가 K이상인 경우 + if min1 >= K: + return count + # 두 번째로 맵지 않은 음식이 존재하는 경우 + if scoville: + min2 = heapq.heappop(scoville) + # 섞은 음식의 스코빌 지수를 계산하여 queue에 넣어줌 + heapq.heappush(scoville, min1 + 2 * min2) + count += 1 + return -1 + + +print(solution([1, 2, 3, 9, 10, 12], 7)) \ No newline at end of file diff --git a/choieungi/main.py b/choieungi/main.py index b210d9c..7cf5f50 100644 --- a/choieungi/main.py +++ b/choieungi/main.py @@ -1,42 +1,13 @@ -from datetime import datetime, timedelta +import heapq - -# take time = count number? - -def count_num(start, times): - cnt = 0 - d = timedelta(milliseconds=999) - for j in times: - if j[0] <= start + d and j[0] >= start: - cnt += 1 - elif j[1] >= start and j[1] <= start + d: - cnt += 1 - elif j[0] >= start and start + d >= j[1]: - cnt += 1 - elif j[0] <= start and j[1] >= start + d: - cnt += 1 - return cnt - - -def solution(lines): - times = [] - for i in lines: - temp = i.split() - t = temp[2][:-1] # remove 's' - if len(t) == 1: - take_time = timedelta(seconds=(int(t))) - timedelta(milliseconds=1) # +999 - else: - a = t.split(".") - take_time = timedelta(seconds=int(a[0]), milliseconds=int(a[1])) - timedelta(milliseconds=1) - end_time = datetime.strptime(temp[0] + temp[1], '%Y-%m-%d%H:%M:%S.%f') - times.append((end_time - take_time, end_time)) # (start_time, end_time) - - # times.sort(key = lambda x: x[0]) input이 이미 정렬됨. +def solution(scoville, K): answer = 0 - for i in times: - start = i[0] - answer = max(count_num(start, times), answer) - start = i[1] - answer = max(count_num(start, times), answer) + heapq.heapify(scoville) + while scoville[0]=2: + heapq.heappush(scoville, (heapq.heappop(scoville))+heapq.heappop(scoville)*2) + answer+=1 + else: + return -1 return answer \ No newline at end of file diff --git "a/choieungi/programmers/lv2/\353\215\224\353\247\265\352\262\214/\353\215\224\353\247\265\352\262\214.py" "b/choieungi/programmers/lv2/\353\215\224\353\247\265\352\262\214/\353\215\224\353\247\265\352\262\214.py" new file mode 100644 index 0000000..7cf5f50 --- /dev/null +++ "b/choieungi/programmers/lv2/\353\215\224\353\247\265\352\262\214/\353\215\224\353\247\265\352\262\214.py" @@ -0,0 +1,13 @@ +import heapq + +def solution(scoville, K): + answer = 0 + heapq.heapify(scoville) + while scoville[0]=2: + heapq.heappush(scoville, (heapq.heappop(scoville))+heapq.heappop(scoville)*2) + answer+=1 + else: + return -1 + + return answer \ No newline at end of file diff --git "a/choieungi/programmers/lv2/\354\206\214\354\210\230\354\260\276\352\270\260/find_primary.py" "b/choieungi/programmers/lv2/\354\206\214\354\210\230\354\260\276\352\270\260/find_primary.py" new file mode 100644 index 0000000..817283e --- /dev/null +++ "b/choieungi/programmers/lv2/\354\206\214\354\210\230\354\260\276\352\270\260/find_primary.py" @@ -0,0 +1,23 @@ +from itertools import permutations + +def check_primary(n): + if n == 0 or n == 1: return 0 + temp = 2 + while temp < n / 2 + 1: + if (n % temp == 0): return 0 + temp += 1 + return 1 + + +def solution(numbers): + answer = 0 + nums = [] + numbers = list(numbers) + for i in range(1, len(numbers) + 1): + for j in list(permutations(numbers, i)): + nums.append(int("".join(j))) + + nums = set(nums) + for i in nums: + answer += check_primary(i) + return answer \ No newline at end of file