最小覆盖圆
来源:互联网 发布:网页关键字优化 编辑:程序博客网 时间:2024/06/16 09:13
给你n个点,求一个最小的圆把所有点覆盖。 hdu3007
----------摘自顾研的《浅谈随机化思想在几何问题中的应用》
const int maxn = 508 ;const double eps = 1e-8 ;int dcmp(double x){ if(fabs(x) < eps) return 0 ; if(x > 0) return 1 ; return -1 ;}struct point{ double x , y ; point(){} point(double x , double y){ this->x = x ; this->y = y ; } friend point operator - (const point &a , const point &b){ return point(a.x-b.x , a.y-b.y) ; } double dist(){ return sqrt(x*x + y*y) ; }};/*三角形(p0 , p1 , p2)外接圆圆心cp*/void circle_center(point p0 , point p1 , point p2 , point &cp){ double a1 = p1.x-p0.x , b1 = p1.y-p0.y , c1 = (a1*a1+b1*b1)/2 ; double a2 = p2.x-p0.x , b2 = p2.y-p0.y , c2 = (a2*a2+b2*b2)/2 ; double d = a1 * b2 - a2 * b1 ; cp.x = p0.x + (c1*b2 - c2*b1) / d ; cp.y = p0.y + (a1*c2 - a2*c1) / d ;}void circle_center(point p0 , point p1 , point &cp){ cp.x = (p0.x + p1.x) / 2 ; cp.y = (p0.y + p1.y) / 2 ;}point center ;double radius ;bool point_in(const point &p){ return dcmp((p - center).dist() - radius) < 0 ;}int n ; point a[maxn] ;void min_circle_cover(){ std::random_shuffle(a , a+n) ; // 打乱顺序 radius = 0 ; center = a[0] ; for(int i = 1 ; i < n ; i++) if(! point_in(a[i])){ center = a[i] ; radius = 0 ; for(int j = 0 ; j < i ; j++) if(! point_in(a[j])){ circle_center(a[i] , a[j] , center) ; radius = (a[j] - center).dist() ; for(int k = 0 ; k < j ; k++) if(! point_in(a[k])){ circle_center(a[i] , a[j] , a[k] , center) ; radius = (a[k] - center).dist() ; } } }}int main(){ int i ; while(cin>>n && n){ for(i = 0 ; i < n ; i++) scanf("%lf%lf" ,&a[i].x , &a[i].y) ; min_circle_cover() ; printf("%.2lf %.2lf %.2lf\n" , center.x , center.y , radius) ; } return 0 ;}洗牌函数 random_shuffle(p, p + n);
0 0
- 最小覆盖圆
- hdu4720(最小覆盖圆)
- 最小覆盖圆
- 求最小覆盖圆
- 最小点集覆盖圆
- HDU 3932 最小覆盖圆
- hdu 2215(最小覆盖圆)
- 点集最小覆盖圆
- hdu3007(最小覆盖圆问题)
- 最小覆盖圆(非)
- 最小覆盖圆算法思考
- hdu3007(最小覆盖圆问题)
- BZOJ 1336([Balkan2002]Alien最小圆覆盖-最小覆盖圆)
- hdu 2215 (最小覆盖圆)(目前WA)
- 最小覆盖圆模版 hdu3932 + 模拟退火
- 最小覆盖圆的增量算法
- hdu-3007(计算几何+最小覆盖圆)
- bzoj 2823(计算几何+最小覆盖圆)
- C++算法之 二维数组的查找
- python 中的日期转换
- 第17周项目4-日期结构体
- 第293天(30W+4)
- Centos5.4下载JDK 1.8命令,直接下载
- 最小覆盖圆
- mfc 获取视图窗口指针
- POJ1068 Parencodings ACM解题报告(找规律)
- Unity中的image effect总结
- 树莓派usb摄像头网络监控(定时拍照+网络存储)
- 文字多行超出省略
- 读取纯真IP数据库QQwry.dat的java版程序报数组越界异常问题 .22
- SPEC06
- sqlite3中日期、时间相关操作