博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 3007【最小圆覆盖-随机增量法模板】
阅读量:4670 次
发布时间:2019-06-09

本文共 1478 字,大约阅读时间需要 4 分钟。

#include
#include
#include
#include
using namespace std;const int N=505;int n;double r;struct dian{ double x,y; dian(double X=0,double Y=0) { x=X,y=Y; } dian operator + (const dian &a) const { return dian(x+a.x,y+a.y); } dian operator - (const dian &a) const { return dian(x-a.x,y-a.y); } dian operator * (const double &a) const { return dian(x*a,y*a); } dian operator / (const double &a) const { return dian(x/a,y/a); }}p[N],c;double dis(dian a,dian b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}double cj(dian a,dian b){ return a.x*b.y-a.y*b.x;}dian yx(dian a,dian b,dian c){ dian p=b-a,q=c-a; double c1=(p.x*p.x+p.y*p.y)/2,c2=(q.x*q.x+q.y*q.y)/2,d=cj(p,q); return a+dian(c1*q.y-c2*p.y,c2*p.x-c1*q.x)/d;}int main(){ while(scanf("%d",&n)&&n) { for(int i=1;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y); random_shuffle(p+1,p+1+n); c=p[1],r=0; for(int i=2;i<=n;i++) if(dis(p[i],c)-r>0) { c=p[i],r=0; for(int j=1;j
0) { c=(p[i]+p[j])/2,r=dis(p[j],c); for(int k=1;k
0) c=yx(p[i],p[j],p[k]),r=dis(p[k],c); } } printf("%.2f %.2f %.2f\n",c.x,c.y,r); } return 0;}

转载于:https://www.cnblogs.com/lokiii/p/8503201.html

你可能感兴趣的文章
Spring面试底层原理的那些问题,你是不是真的懂Spring?
查看>>
Java知识导航总图
查看>>
关于Ajax的实现
查看>>
$cast
查看>>
js 把字符串格式化成时间
查看>>
关于老师
查看>>
[Swift]LeetCode212. 单词搜索 II | Word Search II
查看>>
jquery知识点总结二
查看>>
利用map ,找出list里面string类型,长度最小的那个
查看>>
今天真手贱.
查看>>
【转载】如何使用docker部署c/c++程序
查看>>
Android Binder机制(二) ------- 服务的实现
查看>>
[Algorithm] Find first missing positive integer
查看>>
[Angular] @ViewChild and template #refs to get Element Ref
查看>>
[Angular] Show a loading indicator in Angular using *ngIf/else, the as keyword and the async pipe
查看>>
[Angular] Configurable Angular Components - Content Projection and Input Templates
查看>>
[PWA] 17. Cache the photo
查看>>
[RxJS] ReplaySubject with buffer
查看>>
[Firebase] 3. Firebase Simple Login Form
查看>>
AI 线性代数
查看>>