Given three numbers , , . Find Number of squares of dimension required to cover rectangle.
- It’s allowed to cover the surface larger than the rectangle, but the rectangle has to be covered.
- It’s not allowed to break a square.
- The sides of squares should be parallel to the sides of the rectangle.
Input: N = 6, M = 6, a = 4 Output: 4 Input: N = 2, M = 3, a = 1 Output: 6
Approach: An efficient approach is to make an observation and find a formula. The constraint that edges of each square must be parallel to the edges of the rectangle that allows to analyze X and Y axes separately, that is, how many squares of length ‘a’ are needed to cover squares of length ‘m’ and ‘n’ and take the product of these two quantities. The number of small squares of side length ‘a’ required to cover ‘m’ sized square are ceil(m/a). Simillary, number of ‘a’ sized squares required to cover ‘n’ sized square are ceil(n/a).
So, the answer will be ceil(m/a)*ceil(n/a).
Below is the implementation of the above approach:
- Minimum squares to cover a rectangle
- Count squares with odd side length in Chessboard
- Count number of squares in a rectangle
- Number of squares of maximum area in a rectangle
- Find the Side of the smallest Square that can contain given 4 Big Squares
- Find the side of the squares which are inclined diagonally and lined in a row
- Minimum squares to evenly cut a rectangle
- Find the side of the squares which are lined in a row, and distance between the centers of first and last square is given
- Number of jump required of given length to reach a point of form (d, 0) from origin in 2D plane
- Minimum and maximum possible length of the third side of a triangle
- Area of a n-sided regular polygon with given side length
- Rectangle with minimum possible difference between the length and the width
- Number of Larger Elements on right side in a string
- Minimum number of squares whose sum equals to given number n
- Ratio of area of a rectangle with the rectangle inscribed in it
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.