Skip to content

멀쩡한 사각형 #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2022
Merged

멀쩡한 사각형 #38

merged 1 commit into from
Jun 23, 2022

Conversation

NamJwong
Copy link
Owner

@NamJwong NamJwong commented Jun 23, 2022

문제

풀이 후기

이 문제는 보자마자 어떤 수학적인 공식이 적용될거라 생각했다
그래서 서치를 해봤는데 (서치 가능한 코테를 준비 중이니까)
대단한 공식은 아니고 서치를 못하더라도 규칙을 찾으려면 찾을 수 있는 공식이었다

가로 + 세로 - 최대공약수

관련 자료 보기
(tmi지만 초5 수학경시대회에 나온 문제라고 한다 . .)

공식에 최대공약수를 구하는 부분이 있는데 이건 효율적인 방법(유클리드 호제법)으로 풀려면 서치가 꼭 필요했다

다른 사람의 풀이와 비교

좋아요 1등 풀이

function solution(w,h){
    const slope = h / w;
    let result = 0;

    for(let i = 1; i <= w; i++){
        result += Math.ceil(slope * i);
    }

    return ((h * w) - result) * 2;
}

기울기를 이용한 풀이라고 하는데 사실 나도 처음엔 이런 접근을 생각하긴 했다
그런데 부끄럽게도 수포자라 기울기 관련 개념을 다 까먹었다
다음에 공부할 일이 있을지 몰라 남겨놓는다

@NamJwong NamJwong self-assigned this Jun 23, 2022
@NamJwong NamJwong changed the title 풀이 코드 멀쩡한 사각형 Jun 23, 2022
@NamJwong NamJwong merged commit 26d0dba into main Jun 23, 2022
@NamJwong NamJwong deleted the algorithm/#37 branch June 23, 2022 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

멀쩡한 사각형
1 participant