[프로그래머스] 120922 종이자르기 / 문제분석 / Java, Python3 정답

programmers

쉬운 문제라도 문제를 푸는 방법은 다양합니다.

더 명확하고 깔끔한 문제 해결 방법을 아신다면 자유롭게 말씀해주세요.

프로그래머스 120922 종이 자르기

프로그래머스 저작권을 침해하지 않기 위해

문제 보시고 싶으시면 버튼을 눌러주세요.

답변 형식
프로그래머스 120922 자바
프로그래머스 120922 파이썬

가로 길이와 세로길이  M, N을 받아 한 변의 길이가 1인 정사각형을 만들기 위한 최소 가위질 횟수를 구하면 됩니다.

풀이 조건

– 가위질을 할 때 ‘종이를 겹쳐서 자를 수 없다’고 했습니다.

   ->  가위질 횟수에 관한 식은 한 개 입니다.

– 처음 가위질을 통해 한 변의 길이가 1인 정사각형을 만들고. 두 번째 가위질로 모든 변의 길이가 1인 정사각형을 만듭니다.

– 이 문제는 수학문제와 같습니다.

 

가위질 횟수의 총 합은

1. (M-1) + M*(N-1)

2. (N-1) + N*(M-1)

처음 방향이 M이면 1번, N이면 2번 함수입니다.

 

식을 전개한다면

1. M-1+MN-M

2. N-1+MN-N

으로 나옵니다.

결국 1번이나 2번이나 결과는 MN-1 로 같습니다.

class Solution {
    public int solution(int M, int N) {
        int max = Math.max(M, N);
        int min = Math.min(M, N);

        if(max==1) return 0;
        else if(min==1) return max–1;
        else return (max–1)+(max*(min–1));
    }
}
class Solution {
    public int solution(int M, int N) {
        return M*N-1;
    }
}
def solution(M, N):
    nowmax = max(M,N)    
    nowmin = min(M,N)

    return (nowmax–1)+(nowmax*(nowmin–1))
def solution(M, N):
    return M*N–1

“[프로그래머스] 120922 종이자르기 / 문제분석 / Java, Python3 정답”의 83개의 댓글

  1. [9661]majestic777 Login Oficial | Mejores Slots y Depósitos SPEI,Accede a majestic777 para disfrutar las mejores slots en línea. Descarga la apk oficial y realiza tus depósitos vía SPEI de forma rápida. ¡Regístrate y juega ahora! visit: majestic777

  2. [1758]ek33 লগইন ও অ্যাপ ডাউনলোড | বিকাশ দিয়ে অনলাইন স্লট গেম,ek33 লগইন করুন এবং বিকাশ দিয়ে ক্যাসিনো গেমের অভিজ্ঞতা নিন। আমাদের অনলাইন স্লট গেম সাইটে লাইভ ক্যাসিনো খেলার নিয়ম বুঝে আজই শুরু করুন। visit: ek33

  3. [9803]mx711 Login Oficial | Bono de Bienvenida y Slots en Vivo,Entra en mx711 y disfruta de las mejores slots en vivo. Descarga la app oficial y realiza tus depósitos con OXXO de forma rápida. ¡Regístrate y juega ahora! visit: mx711

  4. [6279]for bet Official Login | Online Slots PH with GCash Bonus,Access for bet to enjoy the best online slots PH. Get your GCash casino bonus and explore our expert baccarat strategy guide. Download the app and start playing now. visit: for bet

  5. [8252]4999bdt লগইন ও অ্যাপ ডাউনলোড | বিকাশ ক্যাসিনো ডিপোজিট,4999bdt login করুন এবং অ্যাপ ডাউনলোড করে লাইভ ক্যাসিনো বোনাস অফার উপভোগ করুন। বিকাশ দিয়ে ক্যাসিনো ডিপোজিট করে আজই গেম শুরু করুন। visit: 4999bdt

  6. If you are a sports betting fan then tylekeo88tv is absolutely worth checking out. The live odds update in real time and the cash out feature saved me during a tight match last week. Super responsive support whenever I needed a hand. tylekeo88tv

  7. [4082]winmy15 Login & APK Download | Online Slots Malaysia,Access winmy15 for a seamless gaming experience. Get the winmy15 APK download and enjoy casino deposit via touch n go for easy top-ups. Join now! visit: winmy15

  8. Downloaded the app on my phone and it runs so smoothly even on older devices. I love checking my favorite slots during my lunch break and the daily rewards keep me coming back. Really happy I found this spot ksr777app

댓글 달기

이메일 주소는 공개되지 않습니다.