Đề bài
Xem bản dịchOn each move, choose one rectangle and cut all the way across it, parallel to a side, making two rectangles with positive integer side lengths. Continue until every piece is a square. Squares may have different sizes. Count cuts, not pieces.
Implement rectangle_cutting(height, width).
Input
height: The starting rectangle height.
width: The starting rectangle width.
Output
Return the minimum number of cuts.
Ràng buộc
1 ≤ height, width ≤ 500. Rotation does not change the answer.
Ví dụ
Đầu vào:
width = 3
height = 2
Kết quả mong đợi:
expected = 2
Đầu vào:
long long width = 3;
long long height = 2;
Kết quả mong đợi:
long long expected = 2;
Đầu vào:
long width = 3;
long height = 2;
Kết quả mong đợi:
long expected = 2;
Giải thích
Cut off a 2 × 2 square, leaving a 2 × 1 rectangle. One more cut splits the remainder into two unit squares.
Đầu vào:
width = 4
height = 4
Kết quả mong đợi:
expected = 0
Đầu vào:
long long width = 4;
long long height = 4;
Kết quả mong đợi:
long long expected = 0;
Đầu vào:
long width = 4;
long height = 4;
Kết quả mong đợi:
long expected = 0;
Giải thích
The starting rectangle is already a square.
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.