Codeforces-274C:The Last Hole!(计算几何)

C. The Last Hole!
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Luyi has n circles on the plane. The i-th circle is centered at (xi, yi). At the time zero circles start to grow simultaneously. In other words, the radius of each circle at time t (t > 0) is equal to t. The circles are drawn as black discs on an infinite white plane. So at each moment the plane consists of several black and white regions. Note that the circles may overlap while growing.

Codeforces-274C:The Last Hole!(计算几何)_第1张图片

We define a hole as a closed, connected white region. For instance, the figure contains two holes shown by red border. During growing some holes may be created and it is easy to see that each created hole will disappear eventually. Luyi asks you to find moment of time such that the last hole disappears. In other words, you should find the first moment such that no hole can be seen after that.

Input

The first line of the input contains integer n (1 ≤ n ≤ 100). Each of the next n lines contains two integers xi and yi ( - 104 ≤ xi, yi ≤ 104), indicating the location of i-th circle.

It's guaranteed that no two circles are centered at the same point.

Output

Print the moment where the last hole disappears. If there exists no moment in which we can find holes print -1.

The answer will be considered correct if the absolute or relative error does not exceed 10 - 4.

Examples
input
3
0 0
1 1
2 2
output
-1
input
4
0 0
0 2
2 2
2 0
output
1.414214
input
4
0 1
0 -1
-2 0
4 0
output
2.125000
思路:只有圆心构成锐角三角形和正方形(坐标为整数,不可能构成其他正多边形)时才有洞,锐角三角形构成的洞最后会消失在其外接圆的圆心,正方形构成的洞最后消失在中心。计算最大的时间并判断是否有其它的圆在此之前把这个洞覆盖住。

不过貌似长方形也可以形成孔。

下图是4个圆心分别在(0,0),(0,2),(4,0),(4,2)的圆,最后那个洞形成于这个长方形的中心。

Codeforces-274C:The Last Hole!(计算几何)_第2张图片

#include
using namespace std;
const int MAX=1e5;
struct Point
{
    __int64 x,y;
}p[MAX];
map,int>ma;
int n;
double dis(Point a,Point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
__int64 DIS(Point a,Point b){return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}
double check(double x,double y)
{
    double ans=2e9+7;
    for(int i=0;i>n;
    ma.clear();
    for(int i=0;i1e-10)ans=max(ans,sqrt((x-p[i].x)*(x-p[i].x)+(y-p[i].y)*(y-p[i].y)));
                }
                //判断是否构成锐角三角形
                if(abs(a+b-c)<1e-10||c-a-b>1e-10||abs(a+c-b)<1e-10||b-a-c>1e-10||abs(b+c-a)<1e-10||a-b-c>1e-10)continue;
                if(DIS(p[i],p[j])+DIS(p[i],p[k])<=DIS(p[j],p[k])||DIS(p[j],p[i])+DIS(p[j],p[k])<=DIS(p[i],p[k])||DIS(p[k],p[i])+DIS(p[k],p[j])<=DIS(p[i],p[j]))continue;
                double x1=p[i].x,x2=p[j].x,x3=p[k].x;
                double y1=p[i].y,y2=p[j].y,y3=p[k].y;
                //外接圆圆心公式
                x=( (x1*x1-x2*x2+y1*y1-y2*y2)*(y1-y3)-(x1*x1-x3*x3+y1*y1-y3*y3)*(y1-y2) ) / (2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3));
                y=( (x1*x1-x2*x2+y1*y1-y2*y2)*(x1-x3)-(x1*x1-x3*x3+y1*y1-y3*y3)*(x1-x2) ) / (2*(y1-y2)*(x1-x3)-2*(y1-y3)*(x1-x2));
                res=check(x,y);
                if(abs(res-sqrt((x-p[i].x)*(x-p[i].x)+(y-p[i].y)*(y-p[i].y)))<1e-10||res-sqrt((x-p[i].x)*(x-p[i].x)+(y-p[i].y)*(y-p[i].y))>1e-10)ans=max(ans,sqrt((x-p[i].x)*(x-p[i].x)+(y-p[i].y)*(y-p[i].y)));
            }
        }
    }
    if(ans<0)cout<<-1<




你可能感兴趣的:(计算几何,ACM)