链接: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
正多边形面积公式为 S=1/2*sin (2*pi/n)*n*R*R;
R = a/( 2*sin(pi/n) )
然后,就一直更新面积啦,看需要更新几次,就是答案啦。
用公式写,复杂的也没多大啦QWQ
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const double eps = 1e-6;
#define pi acos(-1.0)
int main()
{
int T,sum=0;;
double N,s,a,b,L;
cin>>T;
while (T--)
{
sum=0;
cin>>N>>a>>L;
s=0.5*sin(2*pi/N)*N*( (a/(2*sin(pi/N)) ) * (a/(2*sin(pi/N)) ) );
while (s>L)
{
a = a * sin( (N-2) * (pi/ (N*2) ) );
s=0.5*sin(2*pi/N)*N*( (a/(2*sin(pi/N)) ) * (a/(2*sin(pi/N)) ) );
//cout<<"s= "<<s<<endl;
sum++;
}
cout<<sum<<endl;
}
}