生活随笔
收集整理的這篇文章主要介紹了
                                
hdu 2215(最小圆覆盖)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
 
                                
                            
                            
                            解題思路:最小圓覆蓋,注意由于樹也有半徑,所以要加上樹的半徑0.5
 
 
 
 
 
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm> 
using namespace std;
const double eps=1e-8;struct Point
{double x,y; 
}p[505];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)); 
} Point circumcenter(const Point &a,const Point &b,const Point &c)
{ //返回三角形的外心 Point ret; double a1=b.x-a.x,b1=b.y-a.y,c1=(a1*a1+b1*b1)/2;double a2=c.x-a.x,b2=c.y-a.y,c2=(a2*a2+b2*b2)/2;double d=a1*b2-a2*b1;ret.x=a.x+(c1*b2-c2*b1)/d;ret.y=a.y+(a1*c2-a2*c1)/d;return ret; 
} void min_cover_circle(Point *p,int n,Point &c,double &r){ //c為圓心,r為半徑 random_shuffle(p,p+n); c=p[0]; r=0;for(int i=1;i<n;i++){if(dis(p[i],c)>r+eps)  //第一個(gè)點(diǎn){ c=p[i]; r=0;for(int j=0;j<i;j++)if(dis(p[j],c)>r+eps) //第二個(gè)點(diǎn){c.x=(p[i].x+p[j].x)/2;c.y=(p[i].y+p[j].y)/2;r=dis(p[j],c);for(int k=0;k<j;k++)if(dis(p[k],c)>r+eps) //第三個(gè)點(diǎn){//求外接圓圓心,三點(diǎn)必不共線 c=circumcenter(p[i],p[j],p[k]); r=dis(p[i],c); } }  }    } 
} int main()
{int n;Point c;double r; while(scanf("%d",&n)==1 && n){for(int i=0;i<n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);min_cover_circle(p,n,c,r);                    printf("%.2lf\n",r + 0.5);                   } return 0;
}
 
 
                            總結(jié)
                            
                                以上是生活随笔為你收集整理的hdu 2215(最小圆覆盖)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
                            
                            
                                如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。