链接:https://www.nowcoder.com/acm/contest/163/D
来源:牛客网
In order to become a magical girl, Thinking-Bear are learning magic circle.
He first drew a regular polygon of N sides, and the length of each side is a.
He want to get a regular polygon of N sides, and the polygon area is no more than L.
He doesn't want to draw a new regular polygon as it takes too much effort.
So he think a good idea, connect the midpoint of each edge and get a new regular polygon of N sides.
How many operations does it need to get the polygon he want?
输入描述:
The first line of the input is T(1≤ T ≤ 100), which stands for the number of test cases you need to solve.
The first line of each case contains three space-separated integers N, a and L (3 ≤ N ≤ 10, 1 ≤ a ≤ 100, 1 ≤ L ≤ 1000).
输出描述:
For each test case, output a single integer.
示例1
输入
复制
1
4 2 3
输出
复制
1
[题意]
正多边形,取每次边的中点构成新的正多边形, 不断取中点, 问第几次操作后,新的小正多边形面积恰好 <= L;
给定 边长 a;
[思路]
公式: 正多边形的面积 是 内部边中点构成的多边形 面积的 倍
多边形边长为 , R 是正多边形半径,边心距 rn
多边形面积: , 把 边长带入得: ,
所以 暴力枚举 第几次时恰好小于 L
[代码]
#include <iostream>
#include <math.h>
#define PI acos(-1)
using namespace std;
const int maxn=1e7+10;
int main()
{
int t;
scanf("%d",&t);
double n,a,l;
while (t--)
{
scanf("%lf%lf%lf",&n,&a,&l);
double s=sin(2*PI/n)*n*a*a/(8.0*sin(PI/n)*sin(PI/n));
double v=sin(PI*(n-2)/(2*n))*sin(PI*(n-2)/(2*n));
int cnt=0;
for (int i=1;i<=maxn;i++)
{
if (s<=l)
break;
cnt++;
s=s*v*1000.0/1000.0;
}
printf("%d\n",cnt);
}
return 0;
}