zoj 1450 Minimal Circle 最小覆盖圆
题目链接: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 最小覆盖圆的更多相关文章
- HDU 3007 Buried memory & ZOJ 1450 Minimal Circle
题意:给出n个点,求最小包围圆. 解法:这两天一直在学这个神奇的随机增量算法……看了这个http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066之后自己写了好久 ...
- ZOJ 1450 Minimal Circle 最小圆覆盖
套了个模板直接上,貌似没有随机化序列 QAQ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #in ...
- Maple trees(最小覆盖圆)
Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- [hdu-3007]Buried memory 最小覆盖圆
大致题意: 平面上有n个点,求一个最小的圆覆盖住所有点 最小覆盖圆裸题 学习了一波最小覆盖圆算法 #include<cstdio> #include<iostream> #in ...
- ZOJ1450 Minimal Circle 最小圆覆盖
ZOJ1450 给定N个点(N<=100)求最小的圆把这些点全部覆盖 考虑对于三角形,可以唯一的找到外接圆,而多边形又可以分解为三角形,所以对于多边形也可以找到唯一的最小覆盖圆. #includ ...
- 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 ...
- hdu 2215 & hdu 3932(最小覆盖圆)
Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- [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 ...
- Judge Route Circle --判断圆路线
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m ...
随机推荐
- Knockout.Js官网学习(click绑定)
前言 click绑定在DOM元素上添加事件句柄以便元素被点击的时候执行定义的JavaScript 函数.大部分是用在button,input和连接a上,但是可以在任意元素上使用. 简单示例 <h ...
- PHP变量作用域以及地址引用问题
作用域的概念: 在PHP脚本的任何位置都可以声明变量,但是,声明变量的位置会大大影响访问变量的范围.这个可以访问的范围称为作用域. 主要的常用的包括:局部变量.全局变量.静态变量. 1.局部变量:就是 ...
- 如何将两个列表变成一个python字典
一个列表是 index = [0, 1, 2, 3, 4, 5, 6] 另一个是 day = ['1', '2', '3', '4', '5', '6', '7' ] 可以使用dict(zip(ind ...
- windows7安装IE11点击图标没反应
可以通过修改 Windows 注册表的方式解决: Win+R 打开“运行”后输入 regedit 打开 注册表编辑器 打开注册表编辑器(regedit)以后,找到注册表项HKEY_CURRENT_US ...
- How to using to code import to GL journal[AX2012]
static void THK_importLedgerJournalTrans(Args _args) { Filename fileName = "C:\\Users\\ksiu3880 ...
- python Django 学习笔记(二)—— 一个简单的网页
1,创建一个django项目 使用django-admin.py startproject MyDjangoSite 参考这里 2,建立视图 from django.http import HttpR ...
- WPF数据双向绑定
设置双向绑定,首先控件要绑定的对象要先继承一个接口: INotifyPropertyChanged 然后对应被绑定的属性增加代码如下: 意思就是当Age这个属性变化时,要通知监听它变化的人. 即:Pr ...
- SegmentFault 2014黑客马拉松 北京 作品demo
1号作品展示——最熟悉的陌生人 app 利用录音(声纹识别)和照片来让好久不见的见面变得不那么尴尬. 2号作品展示——神奇魔镜 app 灵感来自通话<白雪公主>,穿越到今天的“魔镜”功能依 ...
- java软件包的访问权限和继承
public:公共权限,可以修饰类.成员变量和成员函数,不论是否在同一个包中均可自由访问 package wang; //当一个类的权限为public时,类名必须和文件名相同 public class ...
- kettle报错 ../deploy does not exist, please create it.
具体错误如下: Xlib: extension "RANDR" missing on display "localhost:10.0". ::, INFO [K ...