Thinking-Bear magic(几何)

链接: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
本题就在于公式计算,精度这个问题,emmm……
正多边形的几个知识点:(正n边形)圆心角分成n分,每一个角等于其中一个外角,外角等于360/n,即2*PI/n;
正多边形的外接圆的半径等于a/(2*sin(PI/n));a为边长,PI/n为n份圆心角中的一半;
利用外角与相邻小三角形的关系可以得到每条边中点连线之后的新的正n边形的边长,a’=a*cos(PI/n);

#include<bits/stdc++.h>
#define PI 3.1415926535897932384626
using namespace std;
int main()
{
    int t; cin>>t;
    while(t--)
    {
        int n;
        double a,l,s,r,an;
        cin>>n>>a>>l;
        int cnt=0;
        r=a/(2*sin(PI/n)); //外接圆半径
        s=0.5*sin(2*PI/n)*r*r*n;//面积
        while(s>l)
        {
            a=a*cos(PI/n);//新正n边形的边长
            r=a/(2*sin(PI/n)); //外接圆半径
            s=0.5*sin(2*PI/n)*r*r*n;//面积
            cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

附另外一种解法:这里写链接内容

猜你喜欢

转载自blog.csdn.net/a17865569022/article/details/81449492