Last Updated: 11 Dec, 2020

Count Of Plates

Easy
Asked in company
HSBC

Problem statement

You are given 3 Integers ‘n’, ‘R’ & ‘r’ where ‘n’ is the number of plates,

‘R’ is the radius of the table, and ‘r’ is the radius of the ‘n’ plates. The task is to find out whether the given table has enough space to accommodate the given number of plates of radius ‘r’. Consider the table and plates to be round and no plate can be placed above any other.

Each plate must be completely inside the table and must touch the edge of the table. Of course, the plates must not intersect, but they can touch each other.

You have to return true if the table can accommodate the given number of plates else return false.

Input Format :
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.

The first line of each test case contains 3 space-separated integers ‘n’, ‘R’ & ‘r’
Output format :
For each test case, print Yes if the table can accommodate the given number of plates else print No.

Print the output of each test case in a new line.
Note :
You don’t need to print anything. It has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 10^5
1 <= n <= 10^6
1 <= r <= 10^9
1 <= R <= 10^9
1 <= r <= R

Time Limit: 1 sec

Approaches

01 Approach

 

Approach : 

 

Since each plate must touch the table, the center of these plates will lie in a circle of Radius  ( R - r ). 

 

Let us say, all the n plates can be accommodated on the table. In this case, all the plates will touch each other and their center will form a regular polygon.

Now, consider the right angled triangle ABO formed in the figure below : 


 

Clearly, AB = r, AO = R - r and Angle(ABO) = 90 degrees

Also, since we need to place n plates, the center angle will be divided into n equal parts, so 

Angle ( AOB ) = PI / n.


 

Now, we apply trigonometry in the above triangle :

  • sin ( AOB ) = r / ( R - r )

 

  • sin ( PI / n ) =  r / ( R - r )

 

But, since this is the case for most plates to fit, we can derive the general rule as : 


 

  • sin ( PI / n ) > = r / ( R - r ) or,
  • PI  >= n * sin-1 ( r / ( R - r ) )

 

If the above equality holds, then we can return true as all plates can be placed on the table, else we return false.
 

Special Cases : 
 

  • If n=1. Return true only if r<=R holds true.
     
  • If R=r, and n != 1 , then return false.
     

Algorithm : 

  • Make a constant PI = 3.1415927
  • If n=1, we just check if r<=R holds true.
    • If it holds true, we return true. else, we return false.
  • Store the value of r / ( R- r ) in a double variable “angle”.
  • Initialize “sineValue” as Math.asin ( angle ).
  • Multiply the “sineValue” by n
  • Check if “sinValue” <= PI
  • If the above equation holds true, return true. else return false.