Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i find the number of lowest possible square that can fit in the given square

Tags:

c

algorithm

math

let's suppose i have a square of 7x7.i can fill the square with other squares(i.e the squares of dimension 1x1,2x2.....6x6).How can i can fill the square with least possible smaller squares.please help me.

like image 984
user2220890 Avatar asked Nov 12 '22 08:11

user2220890


1 Answers

Consider a square with dimensions s x s. Cutting a smaller square of dimensions m x m out will result in a square of m x m, a square of n x n, and two rectangles of dimensions m x n, where m + n = s.

When s is even, the square can be divided such that m = n, in which case the rectangles will also be squares, resulting in an answer of 4.

However, when s is odd, values of m and n must be chosen such that the resulting rectangle can be filled with the least number of squares possible. There doesn't seem to be an immediately obvious way to figure out the best configuration, so I would suggest coming up with an algorithm to figure out the least number of squares that can be used to fill a rectangle of size m x n (this is a slightly simpler problem and I believe it can be solved with a recursive algorithm). The total number of squares needed will then be equal to 2 x ([number of squares in m x n rectangle] + 1). You can use a loop to check all the sizes of m between 1 and s/2.

Hope that gets you started.

like image 101
Otaia Avatar answered Nov 15 '22 08:11

Otaia