BZOJ 1336([Balkan2002]Alien最小圆覆盖-最小覆盖圆)

1336: [Balkan2002]Alien最小圆覆盖

Time Limit: 1 Sec   Memory Limit: 162 MBSec   Special Judge
Submit: 733   Solved: 360
[ Submit][ Status]

Description

给出N个点,让你画一个最小的包含所有点的圆。

Input

先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000.0)

Output

输出圆的半径,及圆心的坐标

Sample Input

6
8.0 9.0
4.0 7.5
1.0 2.0
5.1 8.7
9.0 2.0
4.5 1.0


Sample Output

5.00
5.00 5.00

HINT

Source


裸的最小覆盖圆

因为输出必须保留10位小数(谁写的SPJ),所以一直过不了。。直到找到标程研究半天终究过了

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<cctype>
#include<cassert>
#include<climits>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define RepD(i,n) for(int i=n;i>=0;i--)
#define MEM(a) memset(a,0,sizeof(a))
#define MEMI(a) memset(a,127,sizeof(a))
#define MEMi(a) memset(a,128,sizeof(a))
#define INF (2139062143)
#define F (1000000009)
#define MAXN (100000+10)
#define MAXXi (10000.0)
#define eps (1e-7)
typedef long long ll;
long double sqr(long double x){return x*x;}
struct P
{
   double x,y;
   P(){}
   P(double _x,double _y):x(_x),y(_y){}
   friend long double dis(P a,P b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}
}a[MAXN];
struct V
{
   double x,y;
   V(){}
   V(P a,P b):x(b.x-a.x),y(b.y-a.y){}
   friend long double operator*(V a,V b){return a.x*b.y-a.y*b.x;}
};
struct C
{
   P o;
   long double r;
   C(){}
   C(P _o,long double _r):o(_o),r(_r){}
   C(P a,P b,P c)
   {
      long double C1=sqr(b.x)-sqr(a.x)+sqr(b.y)-sqr(a.y),C2=sqr(c.x)-sqr(b.x)+sqr(c.y)-sqr(b.y);
      long double A1=2*(b.x-a.x),A2=2*(c.x-b.x),B1=2*(b.y-a.y),B2=2*(c.y-b.y);
      o.x=(C1*B2-C2*B1)/(A1*B2-A2*B1);
      o.y=(C1*A2-C2*A1)/(B1*A2-B2*A1);
      r=dis(o,c);
   }
   C(P a,P b)
   {
      o=P((a.x+b.x)/2,(a.y+b.y)/2);
      r=dis(o,a);
   }
   bool in(P a){return dis(a,o)<=r;}
}st;
int n;
int main()
{
   //freopen("bzoj1336.in","r",stdin);
   scanf("%d",&n);
   For(i,n) scanf("%lf%lf",&a[i].x,&a[i].y);
   while (rand()%6000==0)
   {
      int i=rand()%n+1,j=rand()%n+1;
      if (i^j) swap(a[i],a[j]);
   }
   st=C(a[1],0);
   Fork(i,2,n)
   {
      if (!st.in(a[i]))
      {
         st=C(a[1],a[i]);
   
         Fork(j,2,i-1)
         {
            if (!st.in(a[j]))
            {
               st=C(a[j],a[i]);
               For(k,j-1)
               {
                  if (!st.in(a[k])) st=C(a[j],a[i],a[k]);
               }
            }
         }
      }
   }  
   
   cout.setf(ios::fixed);
   cout.precision(9);
   cout<<st.r<<endl;
   cout<<st.o.x<<' '<<st.o.y<<endl;
   
   //while (1);
   return 0;
}




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值