Blue Bridge Cup: Rectangular Cut (Answer)

topic

[Problem description]
   Xiao Ming has some rectangular materials, and he wants to cut some squares from these rectangular materials.
When he faced a piece of rectangular material, he always cut from the middle, cut out the largest square, and the remaining rectangle, and then cut the remaining rectangular material until all cut into squares. For example, for a piece of material with 5 and 3 on both sides (denoted as 5×3), Xiao Ming will sequentially cut out 4 squares, 3×3, 2×2, 1×1, and 1×1. Now Xiao Ming has a rectangular piece of material with two sides of 2019 and 324 respectively. How many squares will Xiao Ming cut out in the end?
[Answer Submission]
   This is a question that fills in the blanks with the result, you only need to calculate the result and submit it. The result of this question is an integer. Only fill in this integer when submitting the answer. If you fill in the extra content, you will not be able to score.

answer

   21

Code


public class Main{
    
    
    public static void main(String[] args) {
    
    
        int i=2019;
        int j=324;
        int count=0;
        System.out.print(min(i,j,count));
    }
    public static int min(int i,int j,int count){
    
    
        //每调用一次min方法就代表产生了个正方形
        if(i==j){
    
    
            return count+1;
        }else{
    
    
            if(i>j){
    
    
                count = min(i-j,j,count)+1;
            }else{
    
    
                count = min(j-i,i,count)+1;
            }
        }
        return count;
    }
}

Guess you like

Origin blog.csdn.net/qq_47168235/article/details/109096567