标签:define shu live parent selected arc strong uitable put
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2647 Accepted Submission(s): 1074
首先考虑覆盖三个点的情况,有两种情况:
①:三个点都在圆上,则该圆是三角形的外接圆
②:两个点在圆上,第三个点在圆内,且在圆上的两个点之间的线段一定是直径
如果是多个圆,就不停地迭代。
有一点重要的是外接圆的求法,盗图说明:
一溜证明来自zjk大神
#include<cstdio> #include<cstdlib> #include<ctime> #include<cmath> #include<algorithm> #define pf(x) ((x)*(x)) using namespace std; const int N=1e5+1; const double eps=1e-7; struct node{ double x,y; void input(){scanf("%lf%lf",&x,&y);} }p[N],c;int n,X,Y;double r; double get_dis(const node &a,const node &b){ return sqrt(pf(a.x-b.x)+pf(a.y-b.y)); } node get_focus(const node &a,const node &b,const node &c){ node t; double c1=(a.x*a.x-b.x*b.x+a.y*a.y-b.y*b.y)/2.0; double c2=(c.x*c.x-b.x*b.x+c.y*c.y-b.y*b.y)/2.0; t.x=(c1*(c.y-b.y)-c2*(a.y-b.y))/((a.x-b.x)*(c.y-b.y)-(c.x-b.x)*(a.y-b.y)); t.y=(c1*(c.x-b.x)-c2*(a.x-b.x))/((a.y-b.y)*(c.x-b.x)-(c.y-b.y)*(a.x-b.x)); return t; } void work(){ random_shuffle(p+1,p+n+1); c=p[1];r=0; for(int i=2;i<=n;i++){ if(get_dis(p[i],c)+eps>r){ c=p[i];r=0; for(int j=1;j<i;j++){ if(get_dis(p[j],c)+eps>r){ c.x=(p[i].x+p[j].x)/2; c.y=(p[i].y+p[j].y)/2; r=get_dis(c,p[j]); for(int k=1;k<j;k++){ if(get_dis(p[k],c)+eps>r){ c=get_focus(p[i],p[j],p[k]); r=get_dis(c,p[k]); } } } } } } printf("(%.1lf,%.1lf).\n%.1lf\n",c.x,c.y,r); } int main(){ srand(time(0)); while(scanf("%d%d%d",&X,&Y,&n)==3){ for(int i=1;i<=n;i++) p[i].input(); work(); } return 0; }
标签:define shu live parent selected arc strong uitable put
原文地址:http://www.cnblogs.com/shenben/p/6283996.html