- Related Questions & Answers
- Count the number of ways to tile the floor of size n x m using 1 x m size tiles in C++
- Count the number of rhombi possible inside a rectangle of given size in C++
- Program to find latest group of size M using Python
- Find size of a list in Python
- Split String of Size N in Python
- Python program to Find the size of a Tuple
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors in C++
- Program to find number of increasing subsequences of size k in Python
- Find a sorted subsequence of size 3 in linear time in Python\n
- Program to find size of sublist where product of minimum of A and size of A is maximized in Python
- Break a list into chunks of size N in Python
- Find the size of a HashMap in Java
- Program to find number of rectangles that can form the largest square in Python
- Program to count number of palindromes of size k can be formed from the given string characters in Python
- Count of values of x <= n for which (n XOR x) = (n – x) in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have two values n and m; we have to find the number of rectangles of size 2x1 that can be set inside a rectangle of size n x m. There are few conditions, that we have to consider −

Any two small rectangles cannot overlap.

Every small rectangle lies completely inside the bigger one. It is permitted to touch the edges of the bigger rectangle.

So, if the input is like

n = 3, m = 3, then the output will be 4

To solve this, we will follow these steps −

if n mod 2 is same as 0, then

return(n / 2) * m

otherwise when m mod 2 is 0, then

return(m / 2) * n

return (n * m - 1) / 2

Let us see the following implementation to get better understanding −

def count_rect(n, m): if (n % 2 == 0): return (n / 2) * m elif (m % 2 == 0): return (m // 2) * n return (n * m - 1) // 2 n = 3 m = 3 print(count_rect(n, m))

3, 3

4

Advertisements