# BZOJ 2823: [AHOI2012]信号塔

Time Limit: 10 Sec
Memory Limit: 128 MB

Description

Input

N行，每行两个实数用空格分开，分别是第i个队员的坐标X

Output

Sample Input

5

1.200 1.200

2.400 2.400

3.800 4.500

2.500 3.100

3.900 1.300

Sample Output

2.50 2.85 2.10

HINT

1≤N≤500000

#### Code

#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
const double eps=1e-6;
struct Point
{
double x,y;
};
double distan(Point p1,Point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
int n;
Point a[1000005],o;
double r;
void circum(Point p1,Point p2,Point p3)
{
double a=2*(p2.x-p1.x),b=2*(p2.y-p1.y),c=p2.x*p2.x+p2.y*p2.y-p1.x*p1.x-p1.y*p1.y,
d=2*(p3.x-p1.x),e=2*(p3.y-p1.y),f=p3.x*p3.x+p3.y*p3.y-p1.x*p1.x-p1.y*p1.y;
o.x=(b*f-e*c)/(b*d-e*a);
o.y=(d*c-a*f)/(b*d-e*a);
r=distan(p1,o);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
random_shuffle(&a[1],&a[n+1]);
o=a[1],r=0;
for(int i=2;i<=n;i++)
if(distan(o,a[i])>r+eps)
{
o=a[i];r=0;
for(int j=1;j<=i-1;j++)
if(distan(o,a[j])>r+eps)
{
o.x=(a[i].x+a[j].x)/2;
o.y=(a[i].y+a[j].y)/2;
r=distan(o,a[j]);
for(int k=1;k<=j-1;k++)
if(distan(o,a[k])>r+eps)
circum(a[i],a[j],a[k]);
}
}
printf("%.2lf %.2lf %.2lf\n",o.x,o.y,r);
return 0;
}

posted on 2016-03-19 16:22 wuyuhan 阅读(...) 评论(...) 编辑 收藏