CodeForces 630 P. Area of a Star(计算几何)

Description
给出一个圆内接正n角星,给出圆半径r和n,求正n角星的面积
Input
两个数n和r,n是素数(5<=n<=10^9,1<=r<=10^9)
Output
输出正n角星的面积
Sample Input
7 10
Sample Output
108.395919545675
Solution
计算几何
Code

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
const double PI=acos(-1.0);
double n,r;
int main()
{
    while(~scanf("%lf%lf",&n,&r))
    {
        double a,b,c,x,s;
        a=(3.0/(2*n))*PI,b=PI/(2*n),c=PI/n;
        x=r*sin(b)/sin(a);
        s=n*r*x*sin(c);
        printf("%.7lf\n",s);
    }
    return 0;
}

你可能感兴趣的:(CodeForces 630 P. Area of a Star(计算几何))