- 描述
-
hrw最近看到一个有趣的几何题,题目描述是这样的:一个大圆盘里面放入许多小圆盘,每个小圆盘必须接触大圆盘边缘且与其他小圆盘不能相交,但它们可以互相接触,每个小圆盘具有相同的半径,求此条件下能否放入n个小圆盘。
- 输入
- Multiple sets of test data,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.and you can think the pi is 3.1415927 输出
- 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 2 10 10
样例输出 -
YES NO
这道题是一道几何问题,但是题目已经将问题简化了,
只需要求紧贴能放最边缘的小圆盘个数。
求出小圆和大圆半径形成的圆心角就可以了(因为是相切的,所
以小圆半径到切线肯定是垂直的),
然后用360除掉就是能放多少个小圆。
#include <stdio.h>
#include <math.h>
#define PI 3.1415927
int main ( )
{
int n, R, r, cnt;
while ( ~ scanf ( "%d%d%d", &n, &R, &r ) )
{
if ( r == R || 2*r > R ) //最多只能形成一个圆的情况
printf ( n == 1 && r <= R ? "YES\n" : "NO\n" );
//而且小圆半径必须小于等于大圆半径才能放1个
else
{
cnt = ( int )( PI/asin ( r*1.0/( R-r ) ) );
//利用正弦公式圆占的一半圆心角(所以是只需要π就行了)
printf ( cnt >= n ? "YES\n" : "NO\n" );
}
}
return 0;
}