ZOJ1450 Minimal Circle 最小圆覆盖
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 ¢er,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 最小圆覆盖的更多相关文章
- ZOJ 1450 Minimal Circle 最小圆覆盖
套了个模板直接上,貌似没有随机化序列 QAQ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #in ...
- 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 ...
- ZOJ1450 BZOJ1136 BZOJ1137 HDU3932[最小圆覆盖]
Minimal Circle Time Limit: 5 Seconds Memory Limit: 32768 KB You are to write a program to find ...
- [BZOJ 3564] [SHOI2014] 信号增幅仪 【最小圆覆盖】
题目链接:BZOJ - 3564 题目分析 求最小椭圆覆盖,题目给定了椭圆的长轴与 x 轴正方向的夹角,给定了椭圆长轴与短轴的比值. 那么先将所有点旋转一个角度,使椭圆长轴与 x 轴平行,再将所有点的 ...
- [BZOJ 1336] [Balkan2002] Alien最小圆覆盖 【随机增量法】
题目链接:BZOJ - 1336 题目分析 最小圆覆盖有一个算法叫做随机增量法,看起来复杂度像是 O(n^3) ,但是可以证明其实平均是 O(n) 的,至于为什么我不知道= = 为什么是随机呢?因为算 ...
- 【做题】POI2011R1 - Plot——最小圆覆盖&倍增
原文链接 https://www.cnblogs.com/cly-none/p/loj2159.html 题意:给出\(n\)个点,你需要按编号将其划分成不超过\(m\)段连续的区间,使得所有每个区间 ...
- 【BZOJ2823】[AHOI2012]信号塔(最小圆覆盖)
[BZOJ2823][AHOI2012]信号塔(最小圆覆盖) 题面 BZOJ 洛谷 相同的题: BZOJ1 BZOJ2 洛谷 题解 模板题... #include<iostream> #i ...
- bzoj 1336 最小圆覆盖
最小圆覆盖 问题:给定平面上的一个点集,求半径最小的一个圆,使得点集中的点都在其内部或上面. 随机增量算法: 定义:点集A的最小圆覆盖是Circle(A) 定理:如果Circle(A)=C1,且a不被 ...
- LOJ#6360. 复燃「恋之埋火」(最小圆覆盖+高斯消元)
题面 传送门 题解 不难发现最小圆覆盖的随机增量法复杂度还是正确的 所以现在唯一的问题就是给定若干个点如何求一个\(m\)维的圆 其实就是这一题 //minamoto #include<bits ...
随机推荐
- pop(),del A[:], a[:] = b[:]/'str'/可迭代的
s = ['a','ma','shi','ge'] s0 = s.pop(0) #---> 有返回值 print(s,s0) s1 = s.remove('shi') #---> 无返回值 ...
- 第十一节:pandas统计函数
1.pct_change()计算增长比例 2.cov()协方差 3.corr()相关系数 4.rank()数据排名 5.numpy聚合函数
- nyoj 86 找球号(一)(set,map)
找球号(一) 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 在某一国度里流行着一种游戏.游戏规则为:在一堆球中,每个球上都有一个整数编号i(0& ...
- ProxySQL Tutorial : setup in a MySQL replication topology
ProxySQL Tutorial : setup in a MySQL replication topology 时间 2015-09-15 05:23:20 ORACLE数据库技术文刊 原文 h ...
- noip模拟赛 斐波那契
分析:暴力分有90,真良心啊. a,b这么大,连图都建不出来,肯定是有一个规律.把每个点的父节点写出来:0 1 1 12 123 12345 12345678,可以发现每一个循环的长度刚好是斐波那契数 ...
- Android TextView内容过长加省略号
在Android TextView中有个内容过长加省略号的属性,即ellipsize,用法如下: 在xml中: android:ellipsize = "end" //省略号在结尾 ...
- [K/3Cloud] 单据转换插件执行顺序
1.下推事件及顺序 //初始化变量 OnInitVariable(InitVariableEventArgs e) //解析字段映射关系,并构建查询参数.这里可以加入你想要的额外的字段 OnQuery ...
- Linux find常用命令
今天研究一下find的一些常用的命令. find格式:find filepath [-option] [-print|-exec|-ok...] 其中常用的option主要有 -type d|f|s| ...
- Jquery EasyUI动态生成Tab
function addTab(title, url) { if ($('#tt').tabs('exists', title)) { $('#tt').tabs('select', title); ...
- [bzoj1112][POI2008]砖块Klo_非旋转Treap
砖块Klo bzoj-1112 POI-2008 题目大意:$N$柱砖,希望有连续$K$柱的高度是一样的. 你可以选择以下两个动作 1:从某柱砖的顶端拿一块砖出来,丢掉不要了. 2:从仓库中拿出一块砖 ...