알고리즘 공부 10일차

김서영·2024년 1월 9일
0

알고리즘

목록 보기
10/20

1. 백준 - 1, 2, 3 더하기 4

# 백준 15989 1, 2, 3 더하기 4

N = int(input())

lst = [1] * 10001 # 모든 값을 1로 만드는 경우는 1가지 이므로 기본값 1

for i in range(2, 10001): # 2부터 10000까지의 숫자의 경우의 수
    lst[i] += lst[i - 2] # lst[i]에 i에서 2를 뺀 숫자의 경우의 수를 더해줌
    
for i in range(3, 10001):
    lst[i] += lst[i - 3]

for i in range(N):
    n = int(input())
    print(lst[n])

2. 백준 - ZOAC4

# 백준 23971 ZOAC4

import math
H, W, N, M = map(int, input().split())

row = math.ceil(H / (N + 1))
col = math.ceil(W / (M + 1))
print(row * col)

3. 프로그래머스 - 프로세스

def solution(priorities, location):
    answer = 0
    max_location = priorities.index(max(priorities)) # 맨 처음 중요도가 가장 높은 값의 위치
    while True:
        max_val = max(priorities) # 현재 가장 큰 값(제일 중요한 프로세스)
        if (priorities[max_location] == max_val):
            priorities[max_location] = 0 # 가장 중요도가 높은 값을 0으로 리셋
            answer += 1
            if (max_location == location):
                break
        max_location += 1 # 위치를 뒤로 한칸 씩 옮겨주기
        if (max_location >= len(priorities)): # max_location값이 길이를 넘어서면
            max_location = 0 # 0으로 리셋
    return answer

4. 프로그래머스 - 주식가격

def solution(prices):
    answer = [0] * len(prices)
    for i in range(len(prices)):
        cnt = 0
        for j in range(i+1, len(prices)):
            if prices[j] < prices[i]:
                cnt += 1
                break
            else:
                cnt += 1
        answer[i] = cnt
    return answer
profile
개발과 지식의 성장을 즐기는 개발자

0개의 댓글