随机增量算法(a randomized incremental algorithm)

#define sqr(x) ((x)*(x))
#define EPS 1e-4 struct P{
double x, y;
P(double x, double y):x(x),y(y){}
P(P &a, P &b):x(b.x-a.x),y(b.y-a.y){}
P(){}
P mid(P &a){
return P((a.x+x)/, (a.y+y)/);
}
double cross(P &a){
return x*a.y-y*a.x;
}
double len2(){
return sqr(x)+sqr(y);
}
double dis(P &a){
return sqrt(sqr(x-a.x)+sqr(y-a.y));
}
void print(){
printf("%f %f\n", x, y);
}
}; struct Disc{
P o;
double r;
bool cover(P &a){
return r-o.dis(a) >= -EPS;
}
Disc(){}
Disc(P &o, double r):o(o),r(r){}
Disc(P &a, P &b):o(a.mid(b)), r(a.dis(b)/){}
Disc(P &a, P &b, P &c){
double t1=b.len2()-a.len2();
double t2=c.len2()-a.len2();
P p1(a, b), p2(a, c);
double t3=p1.cross(p2)*;
P p3(t1, p1.y), p4(t2, p2.y);
P p5(p1.x, t1), p6(p2.x, t2);
o=P(p3.cross(p4)/t3, p5.cross(p6)/t3);
r=o.dis(a);
}
}; Disc MinDisc(vector<P> &p){
if(p.size()<=) return Disc();
random_shuffle(p.begin(), p.end());
Disc d(p[], p[]);
for(int i=; i<p.size(); i++)
if(!d.cover(p[i])){
d=Disc(p[], p[i]);
for(int j=; j<i; j++)
if(!d.cover(p[j])){
d=Disc(p[i], p[j]);
for(int k=; k<j; k++)
if(!d.cover(p[k]))
d=Disc(p[i], p[j], p[k]);
}
}
return d;
}

最小圆覆盖(Smallest Enclosing Discs)的更多相关文章

  1. 【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)

    1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1573   ...

  2. Bzoj 1336&1337 Alien最小圆覆盖

    1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 162 MBSec  Special Judge Submit: 1473  ...

  3. hdu3007Buried memory(最小圆覆盖)

    链接 普通的暴力复杂度达到O(n^4),对于这题肯定是不行的. 解法:随机增量算法 参考http://www.2cto.com/kf/201208/149602.html algorithm:A.令C ...

  4. [BZOJ 3564] [SHOI2014] 信号增幅仪 【最小圆覆盖】

    题目链接:BZOJ - 3564 题目分析 求最小椭圆覆盖,题目给定了椭圆的长轴与 x 轴正方向的夹角,给定了椭圆长轴与短轴的比值. 那么先将所有点旋转一个角度,使椭圆长轴与 x 轴平行,再将所有点的 ...

  5. [BZOJ 1336] [Balkan2002] Alien最小圆覆盖 【随机增量法】

    题目链接:BZOJ - 1336 题目分析 最小圆覆盖有一个算法叫做随机增量法,看起来复杂度像是 O(n^3) ,但是可以证明其实平均是 O(n) 的,至于为什么我不知道= = 为什么是随机呢?因为算 ...

  6. 最小圆覆盖 hdu 3007

    今天学习了一下最小圆覆盖, 看了一下午都没看懂, 晚上慢慢的摸索这代码,接合着别人的讲解, 画着图跟着代码一步一步的走着,竟然有些理解了. 最小圆覆盖: 给定n个点, 求出半径最小的圆可以把这些点全部 ...

  7. bzoj1336: [Balkan2002]Alien最小圆覆盖

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1336 1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 ...

  8. 【做题】POI2011R1 - Plot——最小圆覆盖&倍增

    原文链接 https://www.cnblogs.com/cly-none/p/loj2159.html 题意:给出\(n\)个点,你需要按编号将其划分成不超过\(m\)段连续的区间,使得所有每个区间 ...

  9. 【BZOJ2823】[AHOI2012]信号塔(最小圆覆盖)

    [BZOJ2823][AHOI2012]信号塔(最小圆覆盖) 题面 BZOJ 洛谷 相同的题: BZOJ1 BZOJ2 洛谷 题解 模板题... #include<iostream> #i ...

随机推荐

  1. Idea maven tomcat 配置热更新 以及 maven jar依赖

    看了视频 实在忍不住上了idea的贼船 不过这玩意确实有点坑爹,因为用的人少,所以很多配置是有问题的 例如maven配置tomcat热更新 以及tomcat的maven配置 我这里放几张图作为备用 配 ...

  2. css3高级运动keyframes

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. onresize方法

    resize()方法可以写在当前页面包含的所有js里

  4. Sublime Text 3 文本编辑器

    1.安装下载 下载地址:http://www.cr173.com/soft/121149.html http://www.xiazaiba.com/html/24343.html 官网 http:// ...

  5. Summary Ranges

    Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...

  6. C# lambda表达式及初始化器

    using System;using System.Collections.Generic; using System.Linq; namespace ConsoleApplication1d { c ...

  7. java系列: 在eclipse中调试时,输入的jsp或者servlet页面的地址要区分大小写

    比如在当前web工程中有一个jsp页面的名字是: Welcome.jsp 在eclipse中调试时,如果在浏览器中输入: http://localhost:8080/MavenWeb/welcome. ...

  8. ubuntu14.04上安装Mysql-5.7.11

    先安装好操作系统   在Mysql官网上下载最新版的Ubuntu Linux专用的Mysql.我这里下载的是:mysql-server_5.7.11-1ubuntu14.04_amd64.deb-bu ...

  9. swifter技巧(100)

    一.swift新元素 Tip1:柯里化 将方法进行柯里化,把接受多个参数的方法变换成接受第一个参数的方法,并且返回接受余下的参数,返回结果的新方法. func addTwoNumbers(a: Int ...

  10. CS:APP2e Y86处理器模拟器∗指南

    CS:APP2e Y86处理器模拟器∗指南 Randal E.Bryant David R. O'Hallaron 2013年7月29日 本文档描述了处理器模拟器,伴随的表示在第4章Y86处理器架构的 ...