hdu2215

 枚举任意3点找其最小覆盖圆
当为钝角三角形时不是外接圆,而是以其最长边为直径的圆;

 当为外接圆时,半径公式为r=abc/4s;

 由正弦定理,a/sinA=b/sinB=c/sinC=2R,

得sinA=a/(2R),

 又三角形面积公式S=(bcsinA)/2,

所以S=(abc)/(4R),

故R=(abc)/(4S).


const  double  eps = 1e-8 ;

int    cmp(double x){
       if(fabs(x) < eps)  return 0 ;
       if(x < eps) return -1 ;
       return   1  ;
}

struct  point{
        double x , y ;
        point(){}
        point(double _x , double _y):x(_x) , y(_y){}
        friend point operator - (const point &a , const point &b){
              return point(a.x-b.x , a.y-b.y) ;
        }
        friend double operator ^ (const point &a , const point &b){
              return a.x * b.y - a.y * b.x ;
        }
        friend bool operator < (const point &a , const point &b){
              if(cmp(a.x - b.x) != 0)  return cmp(a.x - b.x) < 0 ;
              else   return  cmp(a.y - b.y) < 0 ;
        }
        friend bool operator == (const point &a , const point &b){
             return cmp(a.x - b.x) == 0 && cmp(a.y - b.y) == 0 ;
        }
        friend double dis (const point &a , const point &b){
             return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
        }
};

vector<point>  convex_hull(vector<point> &a){
       vector<point>  s(a.size() * 2 + 5) ;
       sort(a.begin() , a.end()) ;
       a.erase( unique(a.begin() , a.end()) , a.end()) ;
       int m = 0  ;
       for(int i = 0 ; i < a.size() ; i++){
            while(m > 1 && cmp((s[m-1] - s[m-2]) ^ (a[i] - s[m-2])) <= 0) m-- ;
            s[m++] = a[i] ;
       }
       int k = m ;
       for(int i = a.size() - 2 ; i >= 0 ; i--){
            while(m > k && cmp((s[m-1] - s[m-2]) ^ (a[i] - s[m-2])) <= 0) m-- ;
            s[m++] = a[i] ;
       }
       s.resize(m) ;
       if(a.size() > 1) s.resize(m-1) ;
       return s ;
}

int  main(){
     int n ,  i  , j , k ;
     vector<point> g ;
     while(cin>>n && n){
          g.resize(n) ;
          for(i = 0 ; i < n ; i++) scanf("%lf%lf" , &g[i].x , &g[i].y) ;

          if(n == 1){
               puts("0.50") ; continue ;
          }
          if(n == 2){
               printf("%.2lf\n" , dis(g[0] , g[1]) * 0.5 + 0.5) ;
               continue  ;
          }

          vector<point> p = convex_hull(g) ;
          double ans = 0  , r ;
          for(i = 0 ; i < p.size() ; i++){
              for(j = i+1 ; j < p.size() ; j++){
                  for(k = j+1 ; k < p.size() ; k++){
                       double a = dis(p[i] , p[j]) ;
                       double b = dis(p[i] , p[k]) ;
                       double c = dis(p[j] , p[k]) ;
                       double s = fabs( (p[i] - p[j]) ^ (p[k] - p[j]) ) * 0.5 ;
                       if(a*a+b*b < c*c || a*a+c*c < b*b || b*b+c*c < a*a)
                             r = max(a , max(b , c)) * 0.5 ;
                       else  r = a*b*c / 4.0 / s  ;

                       ans =  max(ans , r) ;
                  }
              }
          }
          printf("%.2lf\n" , ans + 0.5) ;
     }
     return 0 ;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值