Given an area of N X M. You have infinite number of tiles of size 2i X 2i, where i = 0, 1, 2,… so on. The task is to find minimum number of tiles required to fill the given area with tiles.
Input : N = 5, M = 6. Output : 9 Area of 5 X 6 can be covered with minimum 9 tiles. 6 tiles of 1 X 1, 2 tiles of 2 X 2, 1 tile of 4 X 4. Input : N = 10, M = 5. Output : 14
The idea is to divide the given area into nearest 2i X 2i.
Lets divide the problem into cases:
Case 1: if N is odd and M is even, fill the a row or column with M number of 1 X 1 tiles. Then count the minimum number of tiles for N/2 X M/2 size of area. Similarly, if M is odd and N is even, add N to our answer and find minimum number of tiles for N/2 X M/2 area.
Case 2: If N and M both are odd, fill one row and one column, so add N + M – 1 to the answer and find minimum number of tiles required to fill N/2 X M/2 area.
Case 3: If N and M both are even, calculate the minimum number of tiles required to fill area of N/2 X M/2 area. Because halving both the dimensions doesn’t change the number of tiles required.
Below is the implementation of this approach:
This article is contributed by Anuj Chauhan (anuj0503). 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Minimum area of a Polygon with three points given
- Find minimum area of rectangle with given set of coordinates
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Calculate Volume, Curved Surface Area and Total Surface Area Of Cylinder
- Count ways to express a number as sum of powers
- Area of a Hexagon
- Area of a Circular Sector
- Maximum area of quadrilateral
- Area of Reuleaux Triangle
- Area of a Regular Pentagram
- Area of plot remaining at the end
- Area of Circumcircle of a Right Angled Triangle
- Area of hexagon with given diagonal length
- Find the Surface area of a 3D figure
- Program to calculate area of a Tetrahedron
Improved By : vt_m