[프로그래머스] 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 max1;
        else return (max1)+(max*(min1));
    }
}
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 (nowmax1)+(nowmax*(nowmin1))
def solution(M, N):
    return M*N1

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

  1. Serious players know this isn’t luck; it’s a calculated psychological battlefield. Master the strategy at bet86 legit where analytical thinking meets entertainment value for true mobile warriors executing their plans anywhere, anytime.

  2. [3149]winmyr Official Login | Trusted Online Casino Malaysia Fast Payouts,winmyr offers a secure platform for gaming. Get the app download and explore fast payout slot games with ease. Join the most trusted online casino in Malaysia today. visit: winmyr

  3. Been playing online for years and finally found a site that actually pays out fast. The games load super quick even on my phone and the bonus terms are totally fair. Give it a spin before it goes under the radar. thaden168

  4. I have tried countless platforms over the years and this one stands out for its reliability and fair play. The team really cares about player satisfaction and it shows in every detail. I will keep coming back for more entertainment and great rewards. mr777casino

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

댓글 달기

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