Algorithm
Gerald is setting the New Year table. The table has the form of a circle; its radius equals R. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and have the same radii that equal r. 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. Help Gerald determine whether the table is large enough for n plates.
The first line contains three integers n, R and r (1 ≤ n ≤ 100, 1 ≤ r, R ≤ 1000) — the number of plates, the radius of the table and the plates' radius.
Print "YES" (without the quotes) if it is possible to place n plates on the table by the rules given above. If it is impossible, print "NO".
Remember, that each plate must touch the edge of the table.
4 10 4
YES
5 10 4
NO
1 10 10
YES
The possible arrangement of the plates for the first sample is:
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <cstdio>
#include <cmath>
int main(){
int n(0), R(0), r(0); scanf("%d %d %d", &n, &R, &r);
const double PI = 3.14159265359;
if((n == 1 && r <= R) || (n == 2 && 2 * r <= R) || (n >= 3 && r < R && sin( PI / n) >= 1.0 * r / (1.0 * R - r)) ) {puts("YES");}
else{puts("NO");}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
Demonstration
Codeforces Solution-A. New Year Table-Solution in C, C++, Java, Python