
반응형
문제
문제 설명
input
brown: 갈색 격자의 수
yellow: 노란색 격자의 수
output
카펫의 가로, 세로 크기
가로 길이 >= 세로 길이
입출력 예
10, 2 => [4, 3]
8, 1 => [3, 3]
24, 24 => [8, 6]
코드
import math
def solution(brown, yellow):
answer = []
for length_1 in range(1, math.ceil(yellow/2)+1):
if yellow % length_1 == 0:
length_2 = yellow / length_1
if brown == length_2 * 2 + length_1 * 2 + 4:
length_1 += 2
length_2 += 2
width, height = int(max(length_1, length_2)), int(min(length_1, length_2))
answer = [width, height]
break
return answer
코드 설명
yellow의 가로 = 2
yellow의 세로 = 1
모서리 = 4
brown 개수 = 모서리 + 가로 * 2 + 세로 * 2
반응형
'코테공부' 카테고리의 다른 글
[Python] Summer/Winter Coding(~2018) : 점프와 순간 이동 (0) | 2023.09.30 |
---|---|
[Python] Summer/Winter Coding(~2018) : 영어 끝말잇기 (0) | 2023.09.28 |
[Python] 2017 팁스타운 : 짝지어 제거하기 (0) | 2023.09.26 |
[Python] 연습문제 : 피보나치 수 (0) | 2023.09.25 |
[Python] 연습문제 : 다음 큰 숫자 (0) | 2023.09.25 |