hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分 圆相交面积 难度:1

Description

The city of M is a famous shopping city and its open-air shopping malls are extremely attractive. During the tourist seasons, thousands of people crowded into these shopping malls and enjoy the vary-different shopping. 

Unfortunately, the climate has changed little by little and now rainy days seriously affected the operation of open-air shopping malls―it’s obvious that nobody will have a good mood when shopping in the rain. In order to change this situation, the manager of these open-air shopping malls would like to build a giant umbrella to solve this problem. 

These shopping malls can be considered as different circles. It is guaranteed that these circles will not intersect with each other and no circles will be contained in another one. The giant umbrella is also a circle. Due to some technical reasons, the center of the umbrella must coincide with the center of a shopping mall. Furthermore, a fine survey shows that for any mall, covering half of its area is enough for people to seek shelter from the rain, so the task is to decide the minimum radius of the giant umbrella so that for every shopping mall, the umbrella can cover at least half area of the mall. 
 

Input

The input consists of multiple test cases. 
The first line of the input contains one integer T (1<=T<=10), which is the number of test cases. 
For each test case, there is one integer N (1<=N<=20) in the first line, representing the number of shopping malls. 
The following N lines each contain three integers X,Y,R, representing that the mall has a shape of a circle with radius R and its center is positioned at (X,Y). X and Y are in the range of [-10000,10000] and R is a positive integer less than 2000. 
 

Output

For each test case, output one line contains a real number rounded to 4 decimal places, representing the minimum radius of the giant umbrella that meets the demands.
 

Sample Input

1 2 0 0 1 2 0 1
 

Sample Output

2.0822
 
计算圆相交面积(两圆扇形-中间的四边形),从所有圆圆心出发,二分求直径,然后选择最小即可
这是萌萌smilewsw代码: 
#include <cstdio>

#include <cstdlib>

#include <iostream>

#include <cstring>

#include <cmath>

#include <algorithm>

#define eps 1e-10

#define PI acos(-1.0)

using namespace std;

struct point

{

    double x,y;

};

struct circle

{

    point c;

    double r;

}ci[50];

double dis(point p1,point p2)

{

    return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));

}

double area(point p,double R,circle a)

{



    double d=dis(p,a.c),pp;

    double sa=0,ang1,ang2;

    ang1=acos((a.r*a.r+d*d-R*R)/(2*a.r*d));

    ang2=acos((R*R+d*d-a.r*a.r)/(2*R*d));

    pp=R*sin(ang2);

    sa=ang1*a.r*a.r+ang2*R*R-pp*d;

    return sa;

}

double qsearch(point p,circle a)

{

    double d=dis(p,a.c);

    double l=d,r=sqrt(d*d+a.r*a.r),mid;

    double ans=PI*a.r*a.r/2;

    while(l+eps<r)

    {

        mid=(l+r)/2;

        if(fabs(area(p,mid,a)-ans)<eps)

            return mid;

        else if(ans<area(p,mid,a))

            r=mid;

        else

            l=mid;

    }

    return l;

}

int main()

{

    int t,n;

    point p;

    circle a;

    p.x=2,p.y=0;

    a.c.x=0,a.c.y=0,a.r=1;

    scanf("%d",&t);

    while(t--)

    {

        scanf("%d",&n);

        for(int i=0;i<n;i++)

            scanf("%lf%lf%lf",&ci[i].c.x,&ci[i].c.y,&ci[i].r);

        double minn;

        for(int i=0;i<n;i++)

        {

            double maxn=ci[i].r/sqrt(2.0);

            for(int j=0;j<n;j++)

            {

                if(i==j) continue;

                maxn=max(maxn,qsearch(ci[i].c,ci[j]));

            }

            if(i==0)

                minn=maxn;

            else

                minn=min(minn,maxn);

        }

        printf("%.4f\n",minn);

    }

    return 0;

}

  

你可能感兴趣的:(open)