Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gimquokka committed May 6, 2021
2 parents 6edd850 + 26e8a64 commit 24acb74
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 38 deletions.
Empty file.
23 changes: 23 additions & 0 deletions AejiJeon/programmers/210502sprint/더맵게.py
Original file line number Diff line number Diff line change
@@ -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))
47 changes: 9 additions & 38 deletions choieungi/main.py
Original file line number Diff line number Diff line change
@@ -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]<K:
if len(scoville)>=2:
heapq.heappush(scoville, (heapq.heappop(scoville))+heapq.heappop(scoville)*2)
answer+=1
else:
return -1

return answer
13 changes: 13 additions & 0 deletions choieungi/programmers/lv2/더맵게/더맵게.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import heapq

def solution(scoville, K):
answer = 0
heapq.heapify(scoville)
while scoville[0]<K:
if len(scoville)>=2:
heapq.heappush(scoville, (heapq.heappop(scoville))+heapq.heappop(scoville)*2)
answer+=1
else:
return -1

return answer
23 changes: 23 additions & 0 deletions choieungi/programmers/lv2/소수찾기/find_primary.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 24acb74

Please sign in to comment.