알고리즘

알고리즘 & 자료구조 스터디(10조) 2일차

고래강이 2023. 5. 23. 20:57

Q1011 달나라 여행

이게 왜 안되는지는 의문이여서 구글링 좀 참고했지만 내가 왜 안됬는지 모르기 때문에 나중에 물어봐야지

def spaceShip(x, y):
    distance = y - x
    try:
        if distance == 1:
            return 1
        elif distance == 2:
            return 2
        elif distance == 3:
            return 3
        else:
            raise Exception("")
    except Exception:         
        num1 = distance ** (1/2)     
        num2 = int(distance ** (1/2))   
        if num1 == num2:
            return num2 + (num2 -1)   # (distance * 2) - 1
        else:
            num3 = 0
            for i in range(1, num2 + 1):
                num3 += i
            
            num4 = distance - num3
            count = 0
            for i in range(1, num2 + 1):
                num4 -= i
                count += 1
                if num4 <= i:
                    count += 1
            return count + num2

num = int(input())
for i in range(num):
    x, y = map(int, input().split())
print(spaceShip(x, y))

Q10250 ACM 호텔

마지막 조건문은 꼭대기층에 대한 조건문인데 이 부분에서 좀 막혀서 힘들었음... 꼭대기층 계산하는 것을 조심하자

t = int(input())

for i in range(t):
    h, w, n = map(int, input().split())
    num = n // h + 1
    floor = n % h
    if n % h == 0:
        num = n // h
        floor = h
    print(f'{(floor * 100) + num}')

Q2839 설탕배

정답이 아니라서 좀 더 다듬어야 할 것 같다 나중에 꼭 완성해야지

x, y, z = map(int, input().split())

start = 0
count = 0

while True:
    start + x 
    if start == z:
        break
    count += 1
    start - y
print(count)