tjut 3007
来源:互联网 发布:emba mba 区别 知乎 编辑:程序博客网 时间:2024/06/05 16:38
#include<iostream> #include<cmath> #include<cstdio> #include<algorithm> using namespace std; const double eps=1e-8; struct Point{ double x,y; }p[505]; double dis(const Point &a,const Point &b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } Point circumcenter(const Point &a,const Point &b,const Point &c) { //返回三角形的外心 Point ret; double a1=b.x-a.x,b1=b.y-a.y,c1=(a1*a1+b1*b1)/2; double a2=c.x-a.x,b2=c.y-a.y,c2=(a2*a2+b2*b2)/2; double d=a1*b2-a2*b1; ret.x=a.x+(c1*b2-c2*b1)/d; ret.y=a.y+(a1*c2-a2*c1)/d; return ret; } void min_cover_circle(Point *p,int n,Point &c,double &r){ //c为圆心,r为半径 random_shuffle(p,p+n); // c=p[0]; r=0; for(int i=1;i<n;i++) { if(dis(p[i],c)>r+eps) //第一个点 { c=p[i]; r=0; for(int j=0;j<i;j++) if(dis(p[j],c)>r+eps) //第二个点 { c.x=(p[i].x+p[j].x)/2; c.y=(p[i].y+p[j].y)/2; r=dis(p[j],c); for(int k=0;k<j;k++) if(dis(p[k],c)>r+eps) //第三个点 {//求外接圆圆心,三点必不共线 c=circumcenter(p[i],p[j],p[k]); r=dis(p[i],c); } } } } } int main(){ int n; Point c; double r; while(scanf("%d",&n)==1 && n){ for(int i=0;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y); min_cover_circle(p,n,c,r); printf("%.2lf %.2lf %.2lf\n",c.x,c.y,r); } return 0; }
0 0
- tjut 3007
- tjut 5289
- tjut 5288
- tjut 5294
- tjut 2586
- tjut 5296
- tjut 5297
- tjut 5299
- tjut 5384
- tjut 5387
- tjut 5386
- tjut 5381
- tjut 5400
- tjut 5399
- tjut 5396
- tjut 5398
- tjut 5412
- tjut 5410
- C#中的where泛型约束
- Universal-Image-Loader源码阅读(2)-utils/L
- 短暂学习Android网络通信
- 关于MATLAB7.0打开提示runtime error问题的全面解决方法
- 友元类(时间)
- tjut 3007
- 使用tesseract3.01字库训练教程完成全国企业信息中心简单验证码的字库建立。
- IPC用户指南/MessageQ模块的使用
- WCF服务开启失败的原因
- spring--入门
- JavaScript中setter和getter方法介绍
- SpringMVC框架使用注解执行定时任务
- 5.百度推送
- android端购物车的实现