计算正多边形的面积 Gym - 101840G

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Let_life_stop/article/details/81914094

http://codeforces.com/gym/101840/attachments

题目大意:输入n,r,k 。n代表往外扩张几次,r代表圆的内接圆半径,k代表多边形的边长。问你每次扩张多边形和内接圆的面积之和。

公式: 多边形的面积公式  0.5*sin(2*3.1415926/n)*n*r*r.(r 代表园的外接圆半径)。

#include<bits/stdc++.h>
using namespace std;
# define maxn 100000+10
# define pi acos(-1)//π 
int main()
{
     freopen("glorious.in","r",stdin);
    int T;
    //cout<<pi<<endl;
    cin>>T;
    int num=0;
    while(T--)
    {
        double  n=0,r=0,k=0;
        cin>>n>>r>>k;
        double temp=0;
        for(int i=1; i<=n; i++)
        {
            double sum,r1;
            double jiaodu=(k-2)*pi/(k*2);//多边形的外接圆半径
//cout<<sin(jiaodu)<<endl;
            r1=r/sin(jiaodu);
         //   cout<<r1<<endl;
            double s=pi*2.0/k;
            sum=0.5*sin(s)*k*r1*r1;
            temp+=(sum-pi*r*r);
            r=r1;//第二次的园的内接圆半径等于第一次正多边形的外接圆的半径
        }
        cout<<"Case "<<++num<<": "<<fixed<<setprecision(5)<<temp<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Let_life_stop/article/details/81914094
今日推荐