diff --git a/Seryeong/Baekjoon/DP/17626.py b/Seryeong/Baekjoon/DP/17626.py new file mode 100644 index 0000000..89cea93 --- /dev/null +++ b/Seryeong/Baekjoon/DP/17626.py @@ -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]) diff --git a/Seryeong/Baekjoon/Greedy/16953.py b/Seryeong/Baekjoon/Greedy/16953.py new file mode 100644 index 0000000..22ff6da --- /dev/null +++ b/Seryeong/Baekjoon/Greedy/16953.py @@ -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) diff --git a/Seryeong/Baekjoon/Implement/15787.py b/Seryeong/Baekjoon/Implement/15787.py new file mode 100644 index 0000000..9646eb1 --- /dev/null +++ b/Seryeong/Baekjoon/Implement/15787.py @@ -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) diff --git "a/Seryeong/Programmers/Lv1/K\353\262\210\354\247\270\354\210\230.py" "b/Seryeong/Programmers/Lv1/K\353\262\210\354\247\270\354\210\230.py" new file mode 100644 index 0000000..eac456d --- /dev/null +++ "b/Seryeong/Programmers/Lv1/K\353\262\210\354\247\270\354\210\230.py" @@ -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 diff --git "a/Seryeong/Programmers/Lv2/\353\215\224\353\247\265\352\262\214.py" "b/Seryeong/Programmers/Lv2/\353\215\224\353\247\265\352\262\214.py" new file mode 100644 index 0000000..fcb7178 --- /dev/null +++ "b/Seryeong/Programmers/Lv2/\353\215\224\353\247\265\352\262\214.py" @@ -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