0 0 0 4 1 0 1 4 0 0 0 0 0 0 0 0
0.5 0 2
Andrew Stankevich Contest 22
这题是几何题,先把线段的端点都连起来,共4条线段,然后选择最短的那条线段,取这条线段的中点,中点即为圆心,半线段长为l1,算出这个点到另外两点连线的较小长度l2,然后圆的半径就是(l1+l2)/2;
#include<iostream> #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<map> #include<string> using namespace std; #define inf 88888888 struct node{ double dis,x,y,xx,yy; }a[10]; struct student{ double x,y; }b[10]; double dist(double x,double y ,double xx,double yy){ return sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy)); } bool cmp(node a,node b){ double temp; if(a.dis>b.dis){ temp=a.x;a.x=b.x;b.x=temp; temp=a.xx;a.xx=b.xx;b.xx=temp; temp=a.yy;a.yy=b.yy;b.yy=temp; temp=a.y;a.y=b.y;b.y=temp; return a.dis<b.dis; } return a.dis<b.dis; } int main() { int n,m,i,j; double x,y,dis1,dis2,x2,y2,x3,y3,x4,y4,x5,y5,disend,len; while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x2,&y2,&x3,&y3,&x4,&y4,&x5,&y5)!=EOF) { if(x2==0 && y2==0 && x3==0 && y3==0 && x4==0 && y4==0 && x5==0 && y5==0)break; a[1].dis=dist(x3,y3,x5,y5);a[1].x=x3;a[1].y=y3;a[1].xx=x5;a[1].yy=y5; a[2].dis=dist(x2,y2,x4,y4);a[2].x=x2;a[2].y=y2;a[2].xx=x4;a[2].yy=y4; a[3].dis=dist(x3,y3,x4,y4);a[3].x=x3;a[3].y=y3;a[3].xx=x4;a[3].yy=y4; a[4].dis=dist(x2,y2,x5,y5);a[4].x=x2;a[4].y=y2;a[4].xx=x5;a[4].yy=y5; sort(a+1,a+5,cmp); x=(a[1].x+a[1].xx)/2; y=(a[1].y+a[1].yy)/2; b[2].x=x2;b[2].y=y2; b[3].x=x3;b[3].y=y3; b[4].x=x4;b[4].y=y4; b[5].x=x5;b[5].y=y5; len=inf; for(i=2;i<=5;i++){ if((b[i].x==a[1].x && b[i].y==a[1].y) || (b[i].x==a[1].xx && b[i].y==a[1].yy))continue; if(dist(b[i].x,b[i].y,x,y)<len) len=dist(b[i].x,b[i].y,x,y); } disend=(len+a[1].dis/2.0)/2; printf("%.4f %.4f %.4f\n",x,y,disend); } return 0; }