Given a rectanglular floor of (M X N) meters is to be paved with square tiles of (s X s). The task is to find the minimum number of tiles required to pave the rectangular floor.
- It’s allowed to cover the surface larger than the floor, but the floor has to be covered.
- It’s not allowed to break the tiles.
- The sides of tiles should be parallel to the sides of the floor.
Input: 2 1 2
length of floor = 2
breadth of floor = 1
length of side of tile = 2
No of tiles required for paving is 2.
Input: 222 332 5
It is given that edges of each tile must be parallel to edges of the tiles allows us to analyze X and Y axes separately, that is, how many segments of length ‘s’ are needed to cover a segment of length’ and ‘N’ — and take product of these two quantities.
ceil(M/s) * ceil(N/s)
, where ceil(x) is the least integer which is above or equal to x. Using integers only, it is usually written as
((M + s - 1) / s)*((N + s - 1) / s)
Below is the implementation of above approach:
Using ceil function:
# Python 3 implementation of
# above approach
# Function to find the
# number of tiles
def solve(M, N, s):
# no of tiles
ans = ((math.ceil(M / s)) *
(math.ceil(N / s)));
# Driver Code
if __name__ == “__main__”:
# input length and breadth of
# rectangle and side of square
N = 12
M = 13
s = 4
print(solve(M, N, s))
# This code is contributed
# by ChitraNayal
- Minimum number of bottles required to fill K glasses
- Count number of ways to fill a "n x 4" grid using "1 x 4" tiles
- Minimum time required to fill a cistern using N pipes
- Count the number of ways to tile the floor of size n x m using 1 x m size tiles
- Minimum number of operation required to convert number x into y
- Minimum number of changes required to make the given array an AP
- Minimum number of palindromes required to express N as a sum | Set 1
- Minimum number of operations required to reduce N to 1
- Minimum number of palindromes required to express N as a sum | Set 2
- Minimum number of mails required to distribute all the questions
- Minimum Number of Platforms Required for a Railway/Bus Station
- Minimum flips required to maximize a number with k set bits
- Minimum number of swaps required to sort an array | Set 2
- Minimum number of days required to complete the work
- Minimum number of swaps required to sort an array
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.