- Related Questions & Answers
- Maximum of smallest possible area that can get with exactly k cut of given rectangular in C++
- Find maximum number that can be formed using digits of a given number in C++
- Maximum Number of Events That Can Be Attended in C++
- Maximum number of candies that can be bought in C
- Maximum number of parallelograms that can be made using the given length of line segments in C++
- Maximum number of threads that can be created within a process in C
- Maximum number of segments that can contain the given points in C++
- Maximum litres of water that can be bought with N Rupees in C++
- Maximum number of people that can be killed with strength P in C++
- Maximum elements which can be crossed using given units of a and b in C++
- Maximum number of partitions that can be sorted individually to make sorted in C++
- Maximum money that can be withdrawn in two steps in C
- Maximum length cycle that can be formed by joining two nodes of a binary tree in C++
- All possible strings of any length that can be formed from a given string?
- Maximum number of 2×2 squares that can be fit inside a right isosceles triangle 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

We are given the dimensions of the sheet of paper, it’s Length L, and Breadth B. Also, we are given the dimensions of a small rectangle, it’s length l, and breadth b. The goal is to find the maximum number of smaller rectangles that can be cut out of a sheet of paper.

We will do following steps −

Firstly, we will take horizontal alignment, lengths L and l of sheet and rectangle respectively. Start aligning the L by l and B by b and count the rectangles.

Then also do the same in vertical alignments. Count again. Return the maximum value of count.

Let us understand with an example.

**Input**

Sheet L=18, B=6 Rectangle l=4, b=3

**Output**

Maximum rectangles: 8

**Explanation**

Horizontal 18/4=4 6/3=2 2*4=8 rectangles possible Vertical 18/3=6 6/4=1 6*1=6 rectangles possible Maximum rectangles here is 8

**Input**

Sheet L=10, B=6 Rectangle l=4, b=2

**Output**

Maximum rectangles: 6

**Explanation**

Horizontal 10/4=2 6/2=3 2*3=6 rectangles possible Vertical 10/2=5 6/4=1 5*1=5 rectangles possible Maximum rectangles here is 6

The variables Length and Breadth are used to store dimensions of sheet.

The variables len and bre are used to store dimensions of rectangle.

Function maxRectangles (int L, int B, int l, int b) takes dimensions of sheet and rectangle and returns the maximum number of rectangles possible.

Variables numh and numv are used to store the number of rectangles that can be cut horizontally and vertically.

For horizontally, divide cols=L/l and rows=B/b, rectangles possible, numh=cols*rows.

For vertically, divide cols=L/b and rows=B/l, rectangles possible, numv=cols*rows.

Return maximum value as result obtained in above two steps numh or numv.

#include <stdio.h> int maxRectangles (int L, int B, int l, int b){ int numh = 0, numv = 0; // Cut rectangles horizontally if possible if (l <= L && b <= B){ // One rectangle is a single cell int cols = B / b; int rows = L / l; // Total rectangles = total cells numh = rows * cols; } // Cut rectangles vertically if possible if (l <= B && b <= L){ int cols = L / b; int rows = B / l; numv = rows * cols; } // Return the maximum possible rectangles return numh>numv?numh:numv; } // Driver code int main (){ int Length = 18; int Breadth =6; int len = 4, bre = 3; printf("Maximum rectangles: %d",maxRectangles(Length,Breadth,len,bre)); return 0; }

If we run the above code it will generate the following output −

Maximum given sized rectangles that can be cut out of a sheet of paper: 8

Advertisements