题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=450

You are to write a program to find a circle which covers a set of points and has the minimal area. There will be no more than 100 points in one problem.

题意描述:找到一个最小圆能够包含到所有的二维坐标点。

算法分析:最小覆盖圆的做法。

 //最小覆盖圆
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
#define exp 1e-10
#define PI 3.141592654
using namespace std;
const int maxn=+;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y){}
}an[maxn],d;//d:最小覆盖圆的圆心坐标
double r;//最小覆盖圆的半径
typedef Point Vector;
Vector operator + (Vector A,Vector B) {return Vector(A.x+B.x , A.y+B.y); }
Vector operator - (Vector A,Vector B) {return Vector(A.x-B.x , A.y-B.y); }
Vector operator * (Vector A,double p) {return Vector(A.x*p , A.y*p); }
Vector operator / (Vector A,double p) {return Vector(A.x/p , A.y/p); }
int dcmp(double x)
{
if (fabs(x)<exp) return ;
return x< ? - : ;
}
double cross(Vector A,Vector B)
{
return A.x*B.y-B.x*A.y;
}
double dist(Vector A,Vector B)
{
double x=(A.x-B.x)*(A.x-B.x);
double y=(A.y-B.y)*(A.y-B.y);
return sqrt(x+y);
} void MiniDiscWith2Point(Point p,Point q,int n)
{
d=(p+q)/2.0;
r=dist(p,q)/;
int k;
double c1,c2,t1,t2,t3;
for (k= ;k<=n ;k++)
{
if (dist(d,an[k])<=r) continue;
if (dcmp(cross(p-an[k],q-an[k]))!=)
{
c1=(p.x*p.x+p.y*p.y-q.x*q.x-q.y*q.y)/2.0;
c2=(p.x*p.x+p.y*p.y-an[k].x*an[k].x-an[k].y*an[k].y)/2.0;
d.x=(c1*(p.y-an[k].y)-c2*(p.y-q.y))/((p.x-q.x)*(p.y-an[k].y)-(p.x-an[k].x)*(p.y-q.y));
d.y=(c1*(p.x-an[k].x)-c2*(p.x-q.x))/((p.y-q.y)*(p.x-an[k].x)-(p.y-an[k].y)*(p.x-q.x));
r=dist(d,an[k]);
}
else
{
t1=dist(p,q);
t2=dist(q,an[k]);
t3=dist(p,an[k]);
if (t1>=t2 && t1>=t3)
{
d=(p+q)/2.0;
r=dist(p,q)/2.0;
}
else if (t2>=t1 && t2>=t3)
{
d=(an[k]+q)/2.0;
r=dist(an[k],q)/2.0;
}
else
{
d=(an[k]+p)/2.0;
r=dist(an[k],p)/2.0;
}
}
}
}
void MiniDiscWithPoint(Point p,int n)
{
d=(p+an[])/2.0;
r=dist(p,an[])/2.0;
int j;
for (j= ;j<=n ;j++)
{
if (dist(d,an[j])<=r) continue;
else
{
MiniDiscWith2Point(p,an[j],j-);
}
}
} int main()
{
int n;
while (scanf("%d",&n)!=EOF && n)
{
for (int i= ;i<=n ;i++)
{
scanf("%lf%lf",&an[i].x,&an[i].y);
}
if (n==)
{
printf("%lf %lf\n",an[].x,an[].y);
continue;
}
r=dist(an[],an[])/2.0;
d=(an[]+an[])/2.0;
for (int i= ;i<=n ;i++)
{
if (dist(d,an[i])<=r) continue;
else
MiniDiscWithPoint(an[i],i-);
}
printf("%.2lf %.2lf %.2lf\n",d.x,d.y,r);
}
return ;
}

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

  1. HDU 3007 Buried memory & ZOJ 1450 Minimal Circle

    题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...

  2. ZOJ 1450 Minimal Circle 最小圆覆盖

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

  3. Maple trees(最小覆盖圆)

    Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...

  4. [hdu-3007]Buried memory 最小覆盖圆

    大致题意: 平面上有n个点,求一个最小的圆覆盖住所有点 最小覆盖圆裸题 学习了一波最小覆盖圆算法 #include<cstdio> #include<iostream> #in ...

  5. ZOJ1450 Minimal Circle 最小圆覆盖

    ZOJ1450 给定N个点(N<=100)求最小的圆把这些点全部覆盖 考虑对于三角形,可以唯一的找到外接圆,而多边形又可以分解为三角形,所以对于多边形也可以找到唯一的最小覆盖圆. #includ ...

  6. 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 ...

  7. hdu 2215 & hdu 3932(最小覆盖圆)

    Maple trees Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. [LeetCode] Generate Random Point in a Circle 生成圆中的随机点

    Given the radius and x-y positions of the center of a circle, write a function randPoint which gener ...

  9. Judge Route Circle --判断圆路线

    Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m ...

随机推荐

  1. Case When Exists SQL

    The Case-When-Exists expression in Oracle is really handy. Here's an example of how to use it in a s ...

  2. 未能加载文件或程序集“Oracle.Web, Version=2.112.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342”或它的某一个依赖项

    当前系统环境描述: Win7x64+VS2012+IIS7 当前情况描述: 发布Web服务,在浏览的时候出现以下问题:未能加载文件或程序集“Oracle.Web, Version=2.112.1.0, ...

  3. Bootstrap Alert Auto Close

    http://stackoverflow.com/questions/23101966/bootstrap-alert-auto-close http://jsfiddle.net/mfX57/ $( ...

  4. java高级工程师必备知识

    成为Java高级工程师需要掌握哪些核心点? 每 逢长假都会有很多程序员跳槽,十一.过年是跳槽黄金时刻,尤其是过年.过年的时候年终奖到手,没有了多少牵挂,年终同学同事聚会比较多,沟通的就多,各种 工作机 ...

  5. canvas 绘圆加边框

    HTML5中canvas元素,绘制圆形需要使用路径,开始时要取得图形上下文,首先使用路径来勾勒图形的轮廓,然后设置颜色,进行绘制. arc(cx,cy,radius,start_angle,end_a ...

  6. LevelDB源码之四LOG文件

    “LOG文件在LevelDb中的主要作用是系统故障恢复时,能够保证不会丢失数据.因为在将记录写入内存的Memtable之前,会先写入Log文件,这样即使系统发生故障,Memtable中的数据没有来得及 ...

  7. spark性能调优:资源优化

    在开发完Spark作业之后,就该为作业配置合适的资源了.Spark的资源参数,基本都可以在spark-submit命令中作为参数设置.很多Spark初学者,通常不知道该设置哪些必要的参数,以及如何设置 ...

  8. JavaScript相关知识

    JavaScript的语法规则 l JavaScript区分大小写 比如变量a和变量A是不一样的变量,要严格区分大小写 l JavaScript脚本程序须嵌入在HTML文件中 因为javascript ...

  9. C#发送邮件源码

    介绍 SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式.SMTP协议属于TCP/IP协议 ...

  10. 第十章 管理类型(In .net4.5) 之 使用反射

    1. 概述 一个.net程序不仅包含代码和数据,还包含 元数据. 本章介绍如何应用attributes以及如何使用反射来获取它,还有如何使用CodeDom和expression trees来实现在运行 ...