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:
题目大意:n个客人要来,主人有一张半径为R的桌子,还有一批半径为r的盘子,数量无限,这些盘子供客人使用,盘子的摆放要与桌子的边相切,且盘子不能重叠放但可以相挨着放,问这张桌子放上盘子后,能否供n个客人使用。
解题思路:
情况1:如果r>R,那么肯定桌子上放不下任何的盘子
情况2:如果r>(R/2),这种情况盘子肯定过了桌面的圆心,那么此时桌面上只能有一个盘子
情况3:其余情况,要想盘子与桌面相切,那么构建一个新的小圆半径为R-r,使这些盘子的圆心都在这个新的小圆上面,就能使盘子与桌面相切了;要想使盘子不重叠,这些盘子得相切。看图:
一个盘子占用2*这个角,然后看360度是否够n个这样的盘子使用即可。
注意精度,不注意的话会wa在test6上。。。。
代码如下:
#include <cstdio>
#include <cmath>
#define PI acos(-1.0)
int main()
{
int n,R,r;
scanf("%d%d%d",&n,&R,&r);
if(r>R)//盘子比桌子大。。
{
printf("NO\n");
return 0;
}
if(r>(R-r))//这种盘子放上去一定过圆心 ,所以只能放一个
{
if(n==1)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
return 0;
}
double tmp=(double)r/(double)(R-r);
double cta=asin(tmp);//计算角度
if(2.0*PI-2.0*cta*n>-1e-12)//注意精度,这里写>=0都过不了
{
printf("YES\n");
}
else
{
printf("NO\n");
}
return 0;
}