Number of largest circles that can be inscribed in a rectangle
Given two integers L and B representing the length and breadth of a rectangle, the task is to find the maximum number of largest possible circles that can be inscribed in the given rectangle without overlapping.
Examples:
Input: L = 3, B = 8
Output: 2
Explanation:
From the above figure it can be clearly seen that the largest circle with a diameter of 3 cm can be inscribed in the given rectangle.
Therefore, the count of such circles is 2.
Input: L = 2, B = 9
Output: 4
Approach: The given problem can be solved based on the following observations:
- The largest circle that can be inscribed in a rectangle will have diameter equal to the smaller side of the rectangle.
- Therefore, the maximum number of such largest circles possible is equal to ( Length of the largest side ) / ( Length of the smallest side ).
Therefore, from the above observation, simply print the value of ( Length of the largest side ) / ( Length of the smallest side ) as the required result.
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
int totalCircles( int L, int B)
{
if (L > B) {
int temp = L;
L = B;
B = temp;
}
return B / L;
}
int main()
{
int L = 3;
int B = 8;
cout << totalCircles(L, B);
return 0;
}
|
Java
import java.io.*;
import java.util.*;
class GFG
{
static int totalCircles( int L, int B)
{
if (L > B) {
int temp = L;
L = B;
B = temp;
}
return B / L;
}
public static void main(String[] args)
{
int L = 3 ;
int B = 8 ;
System.out.print(totalCircles(L, B));
}
}
|
Python3
def totalCircles(L, B) :
if (L > B) :
temp = L
L = B
B = temp
return B / / L
L = 3
B = 8
print (totalCircles(L, B))
|
C#
using System;
public class GFG
{
static int totalCircles( int L, int B)
{
if (L > B) {
int temp = L;
L = B;
B = temp;
}
return B / L;
}
public static void Main(String[] args)
{
int L = 3;
int B = 8;
Console.Write(totalCircles(L, B));
}
}
|
Javascript
<script>
function totalCircles( L, B)
{
if (L > B) {
var temp = L;
L = B;
B = temp;
}
return B / L;
}
var L = 3;
var B = 8;
document.write(totalCircles(L, B).toString().split( '.' )[0]);
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
21 Apr, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...