题目连接:http://codeforces.com/gym/100338
题目描述:
Problem B. Geometry Problem
Input file: geometry.in
Output file: geometry.out
Time limit: 1 second
Memory limit: 64 megabytes
Peter is studying in the third grade of elementary school. His teacher of geometry often gives him d
home tasks.
At the last lesson the students were studying circles. They learned how to draw circles with com
Peter has completed most of his homework and now he needs to solve the following problem. He i
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
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
ends of the first segment. The second line contains x21, y21, x22, y22 and describes the second segm
the same way.
Input is followed by two lines each of which contains four zeroes these lines must not be processe
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
circle. All numbers in the output file must not exceed 1010 by their absolute values. The jury ma
comparisons of real numbers with the precision of 10−4.
Example
geometry.in
0 0 0 4
1 0 1 4
0 0 0 0
0 0 0 0
0.5 0 2
0.5 0 2
题目大意:平面上有两条线段,求一个圆,与两条直线各有一个交点(不包括端点),输出一组可行解的圆心位置与半径。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
long double dis[4];
long double disc(double x,double y,double x3,double y3)
{
long double r=sqrt((x-x3)*(x-x3) + (y-y3) * (y - y3));
return r;
}
long double xc,yc,r;
double x11[2];
double y11[2];
double x22[2],y22[2];
int main()
{
freopen("geometry.in","r",stdin);
freopen("geometry.out","w",stdout);
while(1)
{
cin>>x11[0]>>y11[0]>>x11[1]>>y11[1];
cin>>x22[0]>>y22[0]>>x22[1]>>y22[1];
if(x11[0]==0&&y11[0]==0&&x11[1]==0&&y11[1]==0&&x22[0]==0&&y22[0]==0&&x22[1]==0&&y22[1]==0)break;
dis[0]=disc(x11[0],y11[0],x22[0],y22[0]);
dis[1]=disc(x11[0],y11[0],x22[1],y22[1]);
dis[2]=disc(x11[1],y11[1],x22[0],y22[0]);
dis[3]=disc(x11[1],y11[1],x22[1],y22[1]);
long double minx=990000000;
int u=-1;
for(int i=0;i<=3;i++)
{
//cout<<dis[i]<<endl;
if(minx>dis[i]){minx=dis[i];u=i;}
}
if(u==0){xc=(x11[0]+x22[0])/2;yc=(y11[0]+y22[0])/2;}
else if(u==1){xc=(x11[0]+x22[1])/2;yc=(y11[0]+y22[1])/2;}
else if(u==2){xc=(x11[1]+x22[0])/2;yc=(y11[1]+y22[0])/2;}
else if(u==3){xc=(x11[1]+x22[1])/2;yc=(y11[1]+y22[1])/2;}
cout<<xc<<" "<<yc<<" "<<dis[u]/2+0.001<<endl;
}
return 0;
}