ZOJ1450 给定N个点(N<=100)求最小的圆把这些点全部覆盖

考虑对于三角形,可以唯一的找到外接圆,而多边形又可以分解为三角形,所以对于多边形也可以找到唯一的最小覆盖圆。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const double eps=1e-10,PI=acos(-1.0); int cmp(double k)
{
return k<-eps ? -1:k>eps ? 1:0;
} const double pi=acos(-1.0); inline double sqr(double x)
{
return x*x;
} struct point
{
double x,y;
point (){}
point (double a,double b):x(a),y(b){}
bool input()
{
return scanf("%lf%lf",&x,&y)!=EOF;
}
friend point operator +(const point &a,const point &b)
{
return point(a.x+b.x,a.y+b.y);
}
friend point operator -(const point &a,const point &b)
{
return point(a.x-b.x,a.y-b.y);
}
friend bool operator ==(const point &a,const point &b)
{
return cmp(a.x-b.x)==0&&cmp(a.y-b.y)==0;
}
friend point operator *(const point &a,const double &b)
{
return point(a.x*b,a.y*b);
}
friend point operator*(const double &a,const point &b)
{
return point(a*b.x,a*b.y);
}
friend point operator /(const point &a,const double &b)
{
return point(a.x/b,a.y/b);
}
double norm()
{
return sqrt(sqr(x)+sqr(y));
}
}; 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;
} bool point_in(const point &p,const point &c,const double r)
{
return cmp((p-c).norm()-r)<=0;
} void min_circle_cover(point a[],int n,point &center,double &radius)
{
radius=0;
center=a[0];
for(int i=1;i<n;i++)if(!point_in(a[i],center,radius))
{
center=a[i];radius=0;
for(int j=0;j<i;j++)if(!point_in(a[j],center,radius)){
circle_center(a[i],a[j],center);
radius=(a[j]-center).norm();
for(int k=0;k<j;k++)if(!point_in(a[k],center,radius)){
circle_center(a[i],a[j],a[k],center);
radius=(a[k]-center).norm();
}
}
}
}
point pp[200];
int main()
{freopen("t.txt","r",stdin);
int n;
while(scanf("%d",&n)!=EOF&&n!=0)
{
for(int i=0;i<n;i++)pp[i].input();
point cen;double r;
min_circle_cover(pp,n,cen,r);
printf("%.2lf %.2lf %.2lf\n",cen.x,cen.y,r);
}
return 0;
}

  

ZOJ1450 Minimal Circle 最小圆覆盖的更多相关文章

  1. ZOJ 1450 Minimal Circle 最小圆覆盖

    套了个模板直接上,貌似没有随机化序列 QAQ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #in ...

  2. ZOJ1450 Minimal Circle

    You are to write a program to find a circle which covers a set of points and has the minimal area. T ...

  3. ZOJ1450 BZOJ1136 BZOJ1137 HDU3932[最小圆覆盖]

    Minimal Circle Time Limit: 5 Seconds      Memory Limit: 32768 KB You are to write a program to find ...

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

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

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

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

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

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

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

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

  8. bzoj 1336 最小圆覆盖

    最小圆覆盖 问题:给定平面上的一个点集,求半径最小的一个圆,使得点集中的点都在其内部或上面. 随机增量算法: 定义:点集A的最小圆覆盖是Circle(A) 定理:如果Circle(A)=C1,且a不被 ...

  9. LOJ#6360. 复燃「恋之埋火」(最小圆覆盖+高斯消元)

    题面 传送门 题解 不难发现最小圆覆盖的随机增量法复杂度还是正确的 所以现在唯一的问题就是给定若干个点如何求一个\(m\)维的圆 其实就是这一题 //minamoto #include<bits ...

随机推荐

  1. django-3 admin开启后台配置并展示表内容

    设置了superuser 之后,可以在run server 后, 通过浏览器访问后台,进行界面配置. 1. python manage.py creatersuperuser 此命令在manage.p ...

  2. Final Battle #1 K题 Fire game

    Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows ...

  3. 3.2.8 sed 的运作

        sed 的工作方式相当直接.命令行上的每个文件会依次打开与读取.如果没有文件,则使用标准输入,文件名“-”(单个破折号)可用于表示标准输入.       [many@avention Desk ...

  4. xtu Shortest Path

    Acceteped : 23   Submit : 61 Time Limit : 5000 MS   Memory Limit : 65536 KB Description 题目描述 N(3≤N≤1 ...

  5. 实现下载pdf文件

    //打开文件//$fileDir为文件路径 $fileName为文件名称$file = fopen($fileDir . DS . $fileName, "r");//输入文件标签 ...

  6. Linux下汇编语言学习笔记67 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  7. Ubuntu 12.04 之 虚拟主机的配置

    Ubuntu 12.04 之 虚拟主机的配置 (1)打开etc/hosts文件 增加: 127.0.0.1 study.ubuntu.com 127.0.0.1 hello.ubuntu.com 12 ...

  8. Remove Element(第一种方法参考别人)

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  9. Eclipse-Java代码规范和质量检查插件-PMD

    PMD是一个源代码分析器. 它发现常见的编程缺陷,如未使用的变量.空catch块.不必要的对象创建等等. 它支持Java.JavaScript.Salesforce.com Apex.PLSQL.Ap ...

  10. html自动换行

    对于div,p等块级元素 正常文字的换行(亚洲文字和非亚洲文字)元素拥有默认的white-space:normal,当定义的宽度之后自动换行html css 1.(IE浏览器)连续的英文字符和阿拉伯数 ...