Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Seryeong/Baekjoon/DP/17626.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 17626 Four Squares
import sys

num = int(sys.stdin.readline())
DP = [0] * (num + 1)

i = 1
while i**2 <= num:
DP[i**2] = 1 # 제곱수는 개수가 1개
i += 1

for i in range(1, num + 1):
if DP[i] != 0: # 제곱수이면 패스(어차피 최소이기 때문에)
continue

j = 1
while j*j <= i: # 아직 개수를 안 셌을 때
if DP[i] == 0:
DP[i] = DP[i - j*j] + DP[j*j] # 제곱수 개수 합치기
else:
DP[i] = min(DP[i], DP[i - j*j] + DP[j*j]) # 최소인 제곱수 개수로 업데이트
j += 1

print(DP[-1])
21 changes: 21 additions & 0 deletions Seryeong/Baekjoon/Greedy/16953.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 16953 A -> B
import sys

A, B = map(int, sys.stdin.readline().split())

cnt = 1
while B != A:
if B % 2 == 0: # 2로 나누어질 때
B = B // 2
elif B % 10 == 1: # 뒷자리가 1로 끝날 때
B = B // 10
else: # 아무 연산도 안될 경우
cnt = -1
break
cnt += 1

if B == 0: # A를 B로 만들 수 없을 때
cnt = -1
break

print(cnt)
21 changes: 21 additions & 0 deletions Seryeong/Baekjoon/Implement/15787.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 15787 기차가 어둠을 헤치고 은하수를
import sys

N, M = map(int, sys.stdin.readline().split())

seats = [[0] * 20 for _ in range(N)]
print(seats)
for _ in range(M):
command = sys.stdin.readline().split()
type = int(command[0])
if type == 1:
if seats[command[1]][command[2]]:
seats[command[1]][command[2]] = 1
elif type == 2:
if not seats[command[1]][command[2]]:
seats[command[1]][command[2]] = 0
elif type == 3:
for i in range(20, -1):
seats[command[1]][i+1] = seats[command[1]][i]

print(seats)
8 changes: 8 additions & 0 deletions Seryeong/Programmers/Lv1/K번째수.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def solution(array, commands):
answer = []
for command in commands:
temp = array
temp = temp[command[0]-1:command[1]]
temp.sort()
answer.append(temp[command[2]-1])
return answer
19 changes: 19 additions & 0 deletions Seryeong/Programmers/Lv2/더맵게.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 정확성: 74.2
# 효율성: 16.1
# 합계: 90.3 / 100.0
# import heapq
# def solution(scoville, K):
# answer = 0
# heapq.heapify(scoville)
# while len(scoville) > 1:
# min1 = heapq.heappop(scoville)
# if min1 >= K:
# break
# min2 = heapq.heappop(scoville)

# scoville.append(min1 + min2 * 2)
# answer += 1

# if scoville[0] < K:
# return -1
# return answer