what size circle would you cut out of the square in order to have a remaining area of 177.5 ^2

Given a paper of size A 10 B. Chore is to cutting the paper into squares of whatever size. Discover the minimum number of squares that can be cut from the paper.

Examples:

Input  : 36 x 30 Output : 5 Explanation :  3 (squares of size 12x12) +  2 (squares of size 18x18)  Input  : four x v Output : v Explanation :  1 (squares of size 4x4) +  4 (squares of size 1x1)

Asked in : Google

Recommended: Please solve it on " Practise " beginning, before moving on to the solution.

We have already discussed the Greedy arroyo to solve this problem in previous article. But the previous arroyo doesn't e'er work. For example, it fails for the higher up kickoff test case. So, in this article we solve this trouble using Dynamic Programming.

Nosotros know that if we want to cut minimum number of squares from the newspaper then we would accept to cut largest foursquare possible from the paper first and largest square volition have aforementioned side equally smaller side of the paper. For example if newspaper accept the size 13 x 29, then maximum foursquare will be of side xiii. then we can cut two square of size thirteen x 13 (29/13 = 2). Now remaining paper will have size three 10 thirteen. Similarly we can cut remaining paper by using 4 squares of size 3 x 3 and 3 squares of 1 x 1. So minimum 9 squares tin can be cut from the Newspaper of size 13 x 29.

dig1

Caption:
minimumSquare is a part which tries to split the rectangle at some position. The office is called recursively for both parts. Endeavour all possible splits and take the one with minimum effect. The base case is when both sides are equal i.e the input is already a square, in which case the consequence is Nosotros are trying to observe the cut which is nearest to the eye which volition lead us to our minimum issue.

Assuming we accept a rectangle with width is Northward and height is M.

  • if (N == Chiliad), then it is a foursquare and nada need to be washed.
  • Otherwise, nosotros tin can split up the rectangle into two other smaller one (N – x, M) and (ten, G), and then it can be solved recursively.
  • Similarly, nosotros can also divide it into (N, K – x) and (N, x)

Also nosotros need to be aware of an border case here which is North=11 and M=13 or vice versa. The following will be the all-time possible answer for the given test instance:

Our Approach will render eight for this case but every bit you can see nosotros tin can cut the paper in 6 squares which is minimum. This happens because there is no vertical or horizontal line that cuts through the whole foursquare in the optimum solution.

Below is the implementation of the in a higher place idea using Dynamic Programming.

C++

#include<bits/stdc++.h>

using namespace std;

const int MAX = 300;

int dp[MAX][MAX];

int minimumSquare( int m, int n)

{

int vertical_min = INT_MAX;

int horizontal_min = INT_MAX;

if (n==thirteen && g==11) return half dozen;

if (m==thirteen && n==11) render 6;

if (one thousand == due north)

render 1;

if (dp[yard][n])

return dp[one thousand][due north];

for ( int i = 1;i<= one thousand/ii;i++)

{

horizontal_min = min(minimumSquare(i, northward) +

minimumSquare(m-i, n), horizontal_min);

}

for ( int j = i;j<= n/2;j++)

{

vertical_min = min(minimumSquare(thousand, j) +

minimumSquare(grand, n-j), vertical_min);

}

dp[1000][north] = min(vertical_min, horizontal_min);

return dp[chiliad][northward];

}

int master()

{

int chiliad = 30, northward = 35;

cout << minimumSquare(g, n);

return 0;

}

Java

import java.io.*;

form GFG {

static int dp[][] = new int [ 300 ][ 300 ];

static int minimumSquare( int yard, int n)

{

int vertical_min = Integer.MAX_VALUE;

int horizontal_min = Integer.MAX_VALUE;

if (due north== 13 && m== 11 ) render 6 ;

if (m== 13 && n== 11 ) return half-dozen ;

if (thou == n)

return 1 ;

if (dp[grand][n] != 0 )

return dp[one thousand][n];

for ( int i = one ; i <= m / ii ; i++)

{

horizontal_min

= Math.min(minimumSquare(i, due north)

+ minimumSquare(one thousand - i, due north),

horizontal_min);

}

for ( int j = ane ; j <= due north / 2 ; j++) {

vertical_min

= Math.min(minimumSquare(thousand, j)

+ minimumSquare(m, n - j),

vertical_min);

}

dp[thousand][northward] = Math.min(vertical_min, horizontal_min);

return dp[g][northward];

}

public static void main(String[] args)

{

int k = 30 , north = 35 ;

System.out.println(minimumSquare(chiliad, due north));

}

}

Python3

MAX = 300

dp = [[ 0 for i in range ( MAX )] for i in range ( MAX )]

def minimumSquare(m, n):

vertical_min = 10000000000

horizontal_min = 10000000000

if n = = 13 and yard = = 11 :

return 6

if g = = thirteen and n = = 11 :

render half dozen

if m = = n:

render 1

if dp[m][due north] ! = 0 :

render dp[grand][n]

for i in range ( 1 , m / / 2 + i ):

horizontal_min = min (minimumSquare(i, n) +

minimumSquare(m - i, n), horizontal_min)

for j in range ( i , n / / 2 + 1 ):

vertical_min = min (minimumSquare(thou, j) +

minimumSquare(m, north - j), vertical_min)

dp[thou][due north] = min (vertical_min, horizontal_min)

render dp[m][northward]

if __name__ = = '__main__' :

1000 = 30

n = 35

print (minimumSquare(one thousand, n))

C#

using System;

grade GFG {

static int [, ] dp = new int [300, 300];

static int minimumSquare( int m, int northward)

{

int vertical_min = int .MaxValue;

int horizontal_min = int .MaxValue;

if (n==13 && m==eleven) return vi;

if (m==13 && northward==xi) return 6;

if (m == n)

return 1;

if (dp[m, northward] != 0)

return dp[1000, northward];

for ( int i = 1; i <= m / 2; i++)

{

horizontal_min

= Math.Min(minimumSquare(i, northward)

+ minimumSquare(m - i, northward),

horizontal_min);

}

for ( int j = 1; j <= n / 2; j++)

{

vertical_min

= Math.Min(minimumSquare(grand, j)

+ minimumSquare(thou, n - j),

vertical_min);

}

dp[k, n] = Math.Min(vertical_min, horizontal_min);

return dp[m, northward];

}

public static void Main()

{

int grand = thirty, northward = 35;

Console.WriteLine(minimumSquare(m, northward));

}

}

Javascript

<script>

allow dp = new Array(300);

for (permit i = 0; i < 300; i++)

{

dp[i] = new Array(300);

for (let j = 0; j < 300; j++)

{

dp[i][j] = 0;

}

}

role minimumSquare(m, n)

{

allow vertical_min = Number.MAX_VALUE;

let horizontal_min = Number.MAX_VALUE;

if (n==13 && g==11) return vi;

if (chiliad==13 && n==11) return 6;

if (thousand == n)

return one;

if (dp[m][n] != 0)

render dp[m][n];

for (let i = 1; i <= parseInt(m / 2, 10); i++)

{

horizontal_min

= Math.min(minimumSquare(i, n)

+ minimumSquare(m - i, northward),

horizontal_min);

}

for (allow j = ane; j <= parseInt(n / ii, x); j++) {

vertical_min

= Math.min(minimumSquare(m, j)

+ minimumSquare(m, n - j),

vertical_min);

}

dp[m][n] = Math.min(vertical_min, horizontal_min);

return dp[m][northward];

}

allow 1000 = 30, north = 35;

certificate.write(minimumSquare(m, n));

</script>

This commodity is contributed by Ayush Govil , Aditya Nihal Kumar Singh and Deepanshu Aggarwal. If y'all like GeeksforGeeks and would like to contribute, y'all tin besides write an article using write.geeksforgeeks.org or mail your commodity to review-squad@geeksforgeeks.org. See your commodity appearing on the GeeksforGeeks main page and help other Geeks.
Delight write comments if you detect anything incorrect, or you want to share more information nigh the topic discussed above.


williamsreir1986.blogspot.com

Source: https://www.geeksforgeeks.org/paper-cut-minimum-number-squares-set-2/

0 Response to "what size circle would you cut out of the square in order to have a remaining area of 177.5 ^2"

إرسال تعليق

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel