-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/IgoAlgo/Problem-Solving
- Loading branch information
Showing
5 changed files
with
68 additions
and
38 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |