Given a rectangle with length l and breadth b, we need to find the minimum number of squares that can cover the surface of the rectangle, given that each square has a side of length a. It is allowed to cover the surface larger than the rectangle, but the rectangle has to be covered. It is not allowed to break the square.
Input : 1 2 3 Output :1 We have a 3x3 square and we need to make a rectangles of size 1x2. So we need only square to cover the rectangle. Input : 11 23 14 Output :2
The only way to actually fill the rectangle optimally is to arrange each square such that it is parallel to the sides of the rectangle.So we just need to find the number of squares to fully cover the length and breadth of the rectangle.
The length of the rectangle is l, and if the side length of the square is a divides l, then there must be l/a squares to cover the full length of l. If l isn’t divisible by a, we need to add 1 to l/a, to round it down.For this we can use the ceil function, as ceil(x) returns the least integer which is above or equal to x.
We can do the same with the rectangle width, and take the number of squares across the width to be ceil(b/a).
So, total number of squares=ceil(m/a) * ceil(n/a).
- Number of squares of side length required to cover an N*M rectangle
- Minimum squares to evenly cut a rectangle
- Count number of squares in a rectangle
- Number of squares of maximum area in a rectangle
- Minimum lines to cover all points
- Minimum cost to cover the given positions in a N*M grid
- Minimum distance to travel to cover all intervals
- Minimum steps needed to cover a sequence of points on an infinite grid
- Find minimum area of rectangle with given set of coordinates
- Rectangle with minimum possible difference between the length and the width
- Paper Cut into Minimum Number of Squares
- Largest subset of rectangles such that no rectangle fit in any other rectangle
- Ratio of area of a rectangle with the rectangle inscribed in it
- Minimum number of squares whose sum equals to given number n
- Program to Calculate the Edge Cover of a Graph
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.
Improved By : chitranayal