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. db2事务日志已满解决办法

    查看事务日志配置(MICRO_11为数据库名称): db2 get db cfg for MICRO_11 运行结果: 日志文件大小(4KB)                         (LOG ...

  2. sed输出指定行

    and line ,8p to line ,8p -e 20p - and line -n:取消默认输出.注意:sed命令会默认把输入行打印到屏幕上,所以如果想精准的控制输出,就需要-n. -e:进行 ...

  3. PHP程序员必须知道的两种日志

    前言 作为一名程序员,比码代码还重要那么一点点的东西就是日志的分析和查询.下面列出常见日志及设置方法. php-fpm 慢日志 php慢日志需要在php-fpm.conf设置,如果使用源码包安装默认请 ...

  4. Python之“Hello World”

    Python之“Hello World” 了解Python: 编译型和解释型 编译:把明文代码执行前,先转换成二进制,在执行.这个过程叫编译 解释器:将明文代码转成二进制的 Linux中,gcc编译, ...

  5. Spring核心技术(八)——Spring自动装载的注解

    本文针对自动装载的一些注解进行描述. 基于注解的容器配置 @Required注解 @Required注解需要应用到Bean的属性的setter方法上面,如下面的例子: public class Sim ...

  6. Rim 边缘光

    边缘光:计算眼睛和模型顶点法线的点积,结果作为强度,和材质输出:顶点和法线平行时,强度最大,垂直时,强度最小.因此将他取反,即同一方向时,强度最小,垂直时,强度最大. -dot(normalize(v ...

  7. python接口自动化测试(一)

    本节开始,开始介绍python的接口自动化测试,首先需要搭建python开发环境,到https://www.python.org/下载python 版本直接安装就以了,建议 下载python2.7.1 ...

  8. hihoCoder#1048 状态压缩·二

    原题地址 位运算的状态压缩太操蛋了,很容易出错...又是数组没开够导致诡异现象(明明某个值是1,莫名其妙就变成0了),害我debug一整天!fuck 代码: #include <iostream ...

  9. codeforces 363A

    #include<stdio.h>//这题挺有意思小学学的算盘 int main() { int n,i,m; while(scanf("%d",&n)!=EO ...

  10. SQLAlchemy(2):多表操作 & 连接方式及原生SQL

    一对多:ForeignKey multitb_models.py import datetime from sqlalchemy import create_engine # 引入 创建引擎 from ...