ACdream1414 Geometry Problem
Problem Description
Peter is studying in the third grade of elementary school. His teacher of geometry often gives him difficult home tasks.
At the last lesson the students were studying circles. They learned how to draw circles with compasses. Peter has completed most of his homework and now he needs to solve the following problem. He is given two segments. He needs to draw a circle which intersects interior of each segment exactly once.
The circle must intersect the interior of each segment, just touching or passing through the end of the segment is not satisfactory.
Help Peter to complete his homework.
At the last lesson the students were studying circles. They learned how to draw circles with compasses. Peter has completed most of his homework and now he needs to solve the following problem. He is given two segments. He needs to draw a circle which intersects interior of each segment exactly once.
The circle must intersect the interior of each segment, just touching or passing through the end of the segment is not satisfactory.
Help Peter to complete his homework.
Input
The input file contains several test cases. Each test case consists of two lines.
The first line of the test case contains four integer numbers x11, y11, x12, y12— the coordinates of the ends of the first segment. The second line contains x21. y21, x22, y22 and describes the second segment in the same way.
Input is followed by two lines each of which contains four zeroes these lines must not be processed.
All coordinates do not exceed 102 by absolute value.
The first line of the test case contains four integer numbers x11, y11, x12, y12— the coordinates of the ends of the first segment. The second line contains x21. y21, x22, y22 and describes the second segment in the same way.
Input is followed by two lines each of which contains four zeroes these lines must not be processed.
All coordinates do not exceed 102 by absolute value.
Output
For each test case output three real numbers — the coordinates of the center and the radius of the circle. All numbers in the output file must not exceed 1010 by
their absolute values. The jury makes all comparisons of real numbers with the precision of 10-4.
Sample Input
0 0 0 4 1 0 1 4 0 0 0 0 0 0 0 0
Sample Output
0.5 0 2
Hint
Source
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;
}