Wannafly挑战赛25 B面积并(简单几何)

题意:链接:https://www.nowcoder.com/acm/contest/197/B
来源:牛客网

cxt有一个正n边形,它的外接圆的圆心位于原点,半径为l。以原点为圆心,r为半径作一个圆,求圆和这个正n边形的面积并。

思路:一开始理解错题意了,以为求重叠的部分,其实是求圆和多边形并起来的面积,两种特殊情况都很好求,主要是相交的时候,举正方形为例,

具体计算看代码。

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int maxn=200005;
const int mod=1e9+7;
const double eps=1e-8;
const long double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll qpow(ll a,ll b){ll t=1;while(b){if(b%2){t=(t*a)%mod;b--;}a=(a*a)%mod;b/=2;}return t;}
int main()
{
    std::ios::sync_with_stdio(false);
    long double n,l,r;
    cin>>n>>l>>r;
    long double c=cos(PI/n)*l,ans;
    if(r>=l)
    {
        ans=PI*r*r;
    }
    else if(r<=c)
    {
        ans=n*l*l*sin(2*PI/n)/2;
    }
    else
    {
        long double d=sqrt(r*r-c*c);
        ans=n*(l*l*sin(2*PI/n)/2-d*c+PI*r*r*(acos(c/r)/PI));
    }
    printf("%.2Lf\n",ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Dilly__dally/article/details/83152976