http://47.93.249.116/problem.php?id=2174

典型的模板题,两圆相交的阴影面积,注意高精度PI=acos-1.0

因为取值很大,半径的查找使用二分来解决即可。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<vector>
#include<math.h>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define N 1009
#define Lson rood<<1
#define Rson rood<<1|1
#define PI acos(-1)
#define eps 1e-8
double q(double x1,double y1,double r1,double x2,double y2,double r2)
{
    double d=1.0*sqrt((x1-x2)*(x1-x2)+1.0*(y1-y2)*(y1-y2));
    if(r1+r2<d+eps) return 0;
    if(d<fabs(r1-r2)+eps)
        return min(PI*r1*r1,PI*r2*r2);
    double x = (d*d + r1*r1 - r2*r2)/(2*d);
    double t1 = acos(x / r1);
    double t2 = acos((d - x)/r2);
    return r1*r1*t1 + r2*r2*t2 - d*r1*sin(t1);
}
int main()
{
     double x1,x2,y1,y2,r1,S;
    while(scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&S)!=EOF)
    {
        LL r=ceil(sqrt((x1-x2)*(x1-x2)+1.0*(y1-y2)*(y1-y2)))+r1,l=1;
        while(l<=r)
        {
            LL mid=(l+r)/2;
            double sum=q(x1,y1,r1,x2,y2,mid);
            if(fabs(sum-S)<0.1)
            {
                printf("%lld\n",mid);
                break;
            }
            if(sum>S)
                r=mid-1;
            else l=mid+1;
        }
    }
    return 0;
}

 

posted on 2018-08-18 19:26  云胡不喜。  阅读(418)  评论(0编辑  收藏  举报