1336: [Balkan2002]Alien最小圆覆盖

1337: 最小圆覆盖

Time Limit: 1 Sec Memory Limit: 162 MBSec Special Judge

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

这两道题是最小圆覆盖的裸题,这里主要讲讲求最小圆覆盖的思路。

最小圆覆盖问题就是让你求一个最小的圆使得它能够刚好覆盖掉给出的点。本蒟蒻学习的是一种期望效率O(n)" role="presentation" style="position: relative;">O(n)O(n)的算法。

那么我们怎么做呢?

首先,我们假设前i−1" role="presentation" style="position: relative;">i−1i−1个点已经被现在的圆给覆盖掉了,现在正在处理第i" role="presentation" style="position: relative;">ii个点,那么我们check" role="presentation" style="position: relative;">checkcheck一波,如果当前点在圆外,我们就重构覆盖前i" role="presentation" style="position: relative;">ii个点的最小覆盖圆,具体操作就是先以i" role="presentation" style="position: relative;">ii为圆心作圆,然后从前i−1" role="presentation" style="position: relative;">i−1i−1个点中找一个点j" role="presentation" style="position: relative;">jj使得j" role="presentation" style="position: relative;">jj在圆外,此时最小覆盖圆应该为i,j" role="presentation" style="position: relative;">i,ji,j中点,然后我们再从前j−1" role="presentation" style="position: relative;">j−1j−1个点中找一个点k" role="presentation" style="position: relative;">kk使得k" role="presentation" style="position: relative;">kk在圆外,这时最小覆盖圆自然应该是三角形ijk" role="presentation" style="position: relative;">ijkijk的外接圆。我们一直这样操作到前i" role="presentation" style="position: relative;">ii个点都能够check" role="presentation" style="position: relative;">checkcheck成功为止。

但这样的话最坏情况不应该是O(n3)" role="presentation" style="position: relative;">O(n3)O(n3)吗?是的,因此我们要在最开始的时候将点随机打乱,这样的话期望的效率就应该是O(n)" role="presentation" style="position: relative;">O(n)O(n)的了。还有就是注意T1336" role="presentation" style="position: relative;">T1336T1336应该保留10" role="presentation" style="position: relative;">1010位小数而不是题目上说的2" role="presentation" style="position: relative;">22位。

T1336" role="presentation" style="position: relative;">T1336T1336代码:

#include<bits/stdc++.h>
#define N 100005
using namespace std;
struct point{double x,y;}p[N],O;
struct line{double a,b,c;};
double r;
inline double mul(double x){return x*x;}
inline double dis(point x,point y){return sqrt(mul(x.x-y.x)+mul(x.y-y.y));}
inline bool in_check(point x){return dis(O,x)<=r;}
inline point calc(line a,line b){return point{(b.c*a.b-a.c*b.b)/(a.a*b.b-a.b*b.a),(b.c*a.a-a.c*b.a)/(a.b*b.a-b.b*a.a)};}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%lf%lf",&p[i].x,&p[i].y);
    random_shuffle(p+1,p+n+1);
    r=0;
    for(int i=1;i<=n;++i){
        if(in_check(p[i]))continue;
        O.x=p[i].x,O.y=p[i].y,r=0;
        for(int j=1;j<i;++j){
            if(in_check(p[j]))continue;
            O.x=(p[i].x+p[j].x)/2,O.y=(p[i].y+p[j].y)/2;
            r=dis(O,p[i]);
            for(int k=1;k<j;++k){
                if(in_check(p[k]))continue;
                O=calc(line{2*(p[i].x-p[k].x),2*(p[i].y-p[k].y),mul(p[k].x)+mul(p[k].y)-mul(p[i].x)-mul(p[i].y)},line{2*(p[i].x-p[j].x),2*(p[i].y-p[j].y),mul(p[j].x)+mul(p[j].y)-mul(p[i].x)-mul(p[i].y)});
                r=dis(p[i],O);
            }
        }
    }
    printf("%.10lf\n%.10lf %.10lf",r,O.x,O.y);
    return 0;
}

T1337" role="presentation" style="position: relative;">T1337T1337代码:

#include<bits/stdc++.h>
#define N 100005
using namespace std;
struct point{double x,y;}p[N],O;
struct line{double a,b,c;};
double r;
inline double mul(double x){return x*x;}
inline double dis(point x,point y){return sqrt(mul(x.x-y.x)+mul(x.y-y.y));}
inline bool in_check(point x){return dis(O,x)<=r;}
inline point calc(line a,line b){return point{(b.c*a.b-a.c*b.b)/(a.a*b.b-a.b*b.a),(b.c*a.a-a.c*b.a)/(a.b*b.a-b.b*a.a)};}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%lf%lf",&p[i].x,&p[i].y);
    random_shuffle(p+1,p+n+1);
    r=0;
    for(int i=1;i<=n;++i){
        if(in_check(p[i]))continue;
        O.x=p[i].x,O.y=p[i].y,r=0;
        for(int j=1;j<i;++j){
            if(in_check(p[j]))continue;
            O.x=(p[i].x+p[j].x)/2,O.y=(p[i].y+p[j].y)/2;
            r=dis(O,p[i]);
            for(int k=1;k<j;++k){
                if(in_check(p[k]))continue;
                O=calc(line{2*(p[i].x-p[k].x),2*(p[i].y-p[k].y),mul(p[k].x)+mul(p[k].y)-mul(p[i].x)-mul(p[i].y)},line{2*(p[i].x-p[j].x),2*(p[i].y-p[j].y),mul(p[j].x)+mul(p[j].y)-mul(p[i].x)-mul(p[i].y)});
                r=dis(p[i],O);
            }
        }
    }
    printf("%.3lf",r);
    return 0;
}

2018.07.04 BZOJ1336&&1337: Balkan2002Alien最小圆覆盖的更多相关文章

  1. BZOJ1336 Balkan2002 Alien最小圆覆盖 【随机增量法】*

    BZOJ1336 Balkan2002 Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=100000, ...

  2. 2018.07.04 BZOJ 2823: AHOI2012信号塔(最小圆覆盖)

    2823: [AHOI2012]信号塔 Time Limit: 10 Sec Memory Limit: 128 MB Description 在野外训练中,为了确保每位参加集训的成员安全,实时的掌握 ...

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

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

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

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

  5. 2018.07.04 POJ 1265 Area(计算几何)

    Area Time Limit: 1000MS Memory Limit: 10000K Description Being well known for its highly innovative ...

  6. 2018.07.04 POJ 1696 Space Ant(凸包卷包裹)

    Space Ant Time Limit: 1000MS Memory Limit: 10000K Description The most exciting space discovery occu ...

  7. 2018.07.04 POJ 1113 Wall(凸包)

    Wall Time Limit: 1000MS Memory Limit: 10000K Description Once upon a time there was a greedy King wh ...

  8. 2018.07.04 POJ 1654 Area(简单计算几何)

    Area Time Limit: 1000MS Memory Limit: 10000K Description You are going to compute the area of a spec ...

  9. 2018.07.04 POJ 3304 Segments(简单计算几何)

    Segments Time Limit: 1000MS Memory Limit: 65536K Description Given n segments in the two dimensional ...

随机推荐

  1. xe DateTimePicker.Date bug

    xe6 bug xe7 ok DateTimePicker1->DateTime.DateString(); DateTimePicker1->DateTime.DateTimeStrin ...

  2. WDA-参考路径

    1. SAP Netweave安装 https://wenku.baidu.com/view/b3ac371a227916888486d77c.html?sxts=1545717961793   2. ...

  3. typscript 语法1

    let isDone: boolean = false; let decLiteral: number = 0xf00d; let names: string = 'boob'; /** 使用模版字符 ...

  4. Eclipse 安装JavaEE插件

    Oxygen版Eclipse 导入项目会自动安装你项目需要的一些插件,但是有时候会安装失败,需要手动安装: 这里以Dynamic Web Project项目为例 打开Eclipse,依次选择Help ...

  5. 使用通用mapper 生成代码

    参考通用mapper 文档:https://github.com/abel533/Mapper/wiki/4.1.mappergenerator 使用maven 的方法: 1,修改pom.xml &l ...

  6. 使用Font Awesome替换你的网站图标(icons 图标)

    http://www.thinkcmf.com/font/icons/ 第一次使用 Font Awesome 发现相当的爽呀!它的图标很全,能够帮你节约时间去找图片.下面就来一起学习吧: 1: 去官方 ...

  7. Java的线程同步

    synchronized获取的锁是对象,而不是函数或语句块. 项目结构 资源类 import java.util.concurrent.TimeUnit; public class myResourc ...

  8. MyBatis多对多查询

    -------------------siwuxie095                                 MyBatis 多对多查询         以订单和商品为例,即 一个订单可 ...

  9. 模块常用snippet

    压缩,文件操作,数据库,md5,json, 压缩 import os, sys, time import zipfile # 解压 filename = 'callofdutyblackopszomb ...

  10. SqlServer 查询死锁,杀死死锁进程*转载

    原文: -- 查询死锁 select request_session_id spid, OBJECT_NAME(resource_associated_entity_id) tableName fro ...