Minimal Circle
Time Limit: 5 Seconds Memory Limit: 32768 KB
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.
Input
The input contains several problems. The first line of each problem is a line containing only one integer N which indicates the number of points to be covered. The next N lines contain N points. Each point is represented by x and y coordinates separated by a space. After the last problem, there will be a line contains only a zero.
Output
For each input problem, you should give a one-line answer which contains three numbers separated by spaces. The first two numbers indicate the x and y coordinates of the result circle, and the third number is the radius of the circle. (use escape sequence %.2f)
Sample Input
2
0.0 0.0
3 0
5
0 0
0 1
1 0
1 1
2 2
0
Sample Output
1.50 0.00 1.50
1.00 1.00 1.41
Source: Asia 1997, Shanghai (Mainland China)
裸题哦
注意求重心的方法
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
const int N=;
const double INF=1e9;
const double eps=1e-;
const double pi=acos(-);
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
} inline int sgn(double x){
if(abs(x)<eps) return ;
else return x<?-:;
} struct Vector{
double x,y;
Vector(double a=,double b=):x(a),y(b){}
bool operator <(const Vector &a)const{
return sgn(x-a.x)<||(sgn(x-a.x)==&&sgn(y-a.y)<);
}
void print(){printf("%lf %lf\n",x,y);}
};
typedef Vector Point;
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 b){return Vector(a.x*b,a.y*b);}
Vector operator /(Vector a,double b){return Vector(a.x/b,a.y/b);}
bool operator ==(Vector a,Vector b){return sgn(a.x-b.x)==&&sgn(a.y-b.y)==;}
double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
double Len(Vector a){return sqrt(Dot(a,a));}
Vector Normal(Vector a){
return Vector(-a.y,a.x);//counterClockwise
};
struct Line{
Point s,t;
Line(){}
Line(Point a,Point b):s(a),t(b){}
};
bool isLSI(Line l1,Line l2){
Vector v=l1.t-l1.s,u=l2.s-l1.s,w=l2.t-l1.s;
return sgn(Cross(v,u))!=sgn(Cross(v,w));
}
Point LI(Line a,Line b){
Vector v=a.s-b.s,v1=a.t-a.s,v2=b.t-b.s;
double t=Cross(v2,v)/Cross(v1,v2);
return a.s+v1*t;
}
Point Circumcenter(Point a,Point b,Point c){
Point p=(a+b)/,q=(a+c)/;
Vector v=Normal(b-a),u=Normal(c-a);
if(sgn(Cross(v,u))==){
if(sgn(Len(a-b)+Len(b-c)-Len(a-c))==) return (a+c)/;
if(sgn(Len(a-b)+Len(a-c)-Len(b-c))==) return (b+c)/;
if(sgn(Len(a-c)+Len(b-c)-Len(a-b))==) return (a+b)/;
}
return LI(Line(p,p+v),Line(q,q+u));
} double minCircleCover(Point p[],int n,Point &c){
random_shuffle(p+,p++n);
c=p[];
double r=;
for(int i=;i<=n;i++)
if(sgn(Len(c-p[i])-r)>){
c=p[i],r=;
for(int j=;j<i;j++)
if(sgn(Len(c-p[j])-r)>){
c=(p[i]+p[j])/,r=Len(c-p[i]);
for(int k=;k<j;k++)
if(sgn(Len(c-p[k])-r)>){
c=Circumcenter(p[i],p[j],p[k]);
r=Len(c-p[i]);
}
}
}
return r;
} int n;
Point p[N],c;
int main(int argc, const char * argv[]){
while(true){
n=read();if(n==) break;
for(int i=;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
double r=minCircleCover(p,n,c);
printf("%.2f %.2f %.2f\n",c.x,c.y,r);
}
}
HDU3932好像还有模拟退火做法
ZOJ1450 BZOJ1136 BZOJ1137 HDU3932[最小圆覆盖]的更多相关文章
-
luoguP1742 最小圆覆盖
最小圆覆盖 首先 没错,我是个蒟蒻.luogu 流程 圆 C; for(i=1 to n) { if(P[i] 不在 C 内) { C = {P[i], 0}; for(j=1 to i-1) { i ...
-
【BZOJ-1336&;1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)
1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 1573 ...
-
Bzoj 1336&;1337 Alien最小圆覆盖
1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec Memory Limit: 162 MBSec Special Judge Submit: 1473 ...
-
hdu3007Buried memory(最小圆覆盖)
链接 普通的暴力复杂度达到O(n^4),对于这题肯定是不行的. 解法:随机增量算法 参考http://www.2cto.com/kf/201208/149602.html algorithm:A.令C ...
-
[BZOJ 3564] [SHOI2014] 信号增幅仪 【最小圆覆盖】
题目链接:BZOJ - 3564 题目分析 求最小椭圆覆盖,题目给定了椭圆的长轴与 x 轴正方向的夹角,给定了椭圆长轴与短轴的比值. 那么先将所有点旋转一个角度,使椭圆长轴与 x 轴平行,再将所有点的 ...
-
[BZOJ 1336] [Balkan2002] Alien最小圆覆盖 【随机增量法】
题目链接:BZOJ - 1336 题目分析 最小圆覆盖有一个算法叫做随机增量法,看起来复杂度像是 O(n^3) ,但是可以证明其实平均是 O(n) 的,至于为什么我不知道= = 为什么是随机呢?因为算 ...
-
最小圆覆盖 hdu 3007
今天学习了一下最小圆覆盖, 看了一下午都没看懂, 晚上慢慢的摸索这代码,接合着别人的讲解, 画着图跟着代码一步一步的走着,竟然有些理解了. 最小圆覆盖: 给定n个点, 求出半径最小的圆可以把这些点全部 ...
-
bzoj1336: [Balkan2002]Alien最小圆覆盖
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1336 1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 ...
-
【做题】POI2011R1 - Plot——最小圆覆盖&;倍增
原文链接 https://www.cnblogs.com/cly-none/p/loj2159.html 题意:给出\(n\)个点,你需要按编号将其划分成不超过\(m\)段连续的区间,使得所有每个区间 ...
随机推荐
-
.NET 数据类型转换 方法
using Newtonsoft.Json;using Newtonsoft.Json.Converters;using System.Web.Script.Serialization; /// &l ...
-
XCode使用自带SVN,SVN命令
转载http://blog.sina.com.cn/s/blog_68661bd80101phpy.html 这两天响应老板要求,把所有代码放到公司的SVN服务器上,按照我的想法肯定是就苹果组建一个服 ...
-
MySQL Cluster2个数据节点压力测试--mysqlslap工具压400W写
锅巴哥的个人建议:cluster叫电信运营商版本,所以基本上在很大的用户并发量的情况下才会用到,对连接数的线性增长要求高的场景,千兆就不用想了, 没万兆就不用玩了. 很不幸,我的就是千兆网络,我的数据 ...
-
用std::thread替换实现boost::thread_group
thread_group是boost库中的线程池类,内部使用的是boost::thread. 随着C++ 11标准的制定和各大编译器的新版本的推出(其实主要是VS2012的推出啦……),本着能用标准库 ...
-
Gulp那些好用的插件 2016.04.20
开始接触LESS.组件化编程后,慢慢意识到需要一个提高工作效率的构建工具,就此接触到了Gulp. Gulp的好处在这里就不细说啦,只有四个API接口学起来简直爽歪歪,减少了大量的I/O操作,用起来很畅 ...
-
UIToolbar+UIWebView 浏览器
创建界面 var webView : UIWebView! var toolBar : UIToolbar! let swiftWH = UIScreen.mainScreen().bounds.si ...
-
用Nginx给网站做一个简单的防盗链
目录结构 Nginx防盗链配置 有些时候,大家不想让别人调用自己的图片,一是因为个人版权的问题,再一点就是会增加服务器的负载.还会产生一些没必要的流量. 其实在Nginx里面,很容易就做到防盗链的,在 ...
-
Flash Actionscript AS3 渐变透明 mask遮罩
把图片变成渐变透明(左图是效果图,右图是原图) var a:Sprite = new Sprite(); a.graphics.beginGradientFill(GradientType.LI ...
-
js的同步异步
由于js没有多线程,所以处理多任务的时候,可以用异步回调来解决.js中setTimeout.setInterval.ajax(jq中可以选择同步或异步)均会开启异步.遇到异步模块,会将其推入值任务队列 ...
-
【error】: &#39;Can&#39;t connect to local MySQL server through socket &#39;/var/run/mysqld/mysqld.sock&#39; (2)&#39;
错误描述如下: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) ...