# bzoj2823[AHOI2012]信号塔

## 2823: [AHOI2012]信号塔

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 1190  Solved: 545
[Submit][Status][Discuss]

i个队员的坐标X

5
1.200 1.200
2.400 2.400
3.800 4.500
2.500 3.100
3.900 1.300

2.50 2.85 2.10

## HINT

1≤N≤500000

 1 #include<bits/stdc++.h>
2 #define N 500010
3 using namespace std;
4 int n;double r;
5 const double eps=1e-8;
6 struct P{
7     double x,y;
8     P operator - (const P &b)const{return (P){x-b.x,y-b.y};}
9     double len(){return sqrt(x*x+y*y);}
10 }a[N],c;
11
12 P getcentre(P A,P B,P C){
13     P ret;
14     double a1=B.x-A.x,b1=B.y-A.y,c1=(a1*a1+b1*b1)/2;
15     double a2=C.x-A.x,b2=C.y-A.y,c2=(a2*a2+b2*b2)/2;
16     double d=a1*b2-a2*b1;
17     ret.x=A.x+(c1*b2-c2*b1)/d;
18     ret.y=A.y+(a1*c2-a2*c1)/d;
19     return ret;
20 }
21
22 void getcircle(){
23     random_shuffle(a+1,a+1+n);
24     c=a[1];r=0;
25     for(int i=1;i<=n;i++){
26         if((a[i]-c).len()>r+eps){
27             c=a[i];r=0;
28             for(int j=1;j<i;j++){
29                 if((a[j]-c).len()>r+eps){
30                     c.x=(a[i].x+a[j].x)/2;
31                     c.y=(a[i].y+a[j].y)/2;
32                     r=(a[j]-c).len();
33                     for(int k=1;k<j;k++){
34                         if((a[k]-c).len()>r+eps){
35                             c=getcentre(a[i],a[j],a[k]);
36                             r=(a[i]-c).len();
37                         }
38                     }
39                 }
40             }
41         }
42     }
43 }
44
45 int main(){
46     scanf("%d",&n);
47     for(int i=1;i<=n;i++)
48     scanf("%lf%lf",&a[i].x,&a[i].y);
49     getcircle();
50     printf("%.2lf %.2lf %.2lf\n",c.x,c.y,r);
51     return 0;
52 }

posted @ 2018-01-21 16:44  _wsy  阅读(176)  评论(0编辑  收藏  举报