几何水题 acdream 1414 Geometry Problem

 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. 
 
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 x  11, y  11, x 12, y  12— the coordinates of the ends of the first segment. The second line contains x  21. y  21, x  22, y  22 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 10  2 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 10  10 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



题意:给你两条线的两个端点,让你给出一个圆的圆心和半径


思路:找出两条线段最近的两个端点,两点的中点为圆心,两点的距离的一半+一个很小的数为半径

ac代码:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;


struct point
{
    double x,y;
};


double dis(point a,point b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}


int main()
{
    point a,b,c,d;
    double p,q,r;
    while(cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>d.y)
    {
        if(a.x==0&&a.y==0&&b.x==0&&b.y==0&&c.x==0&&c.y==0&&d.x==0&&d.y==0)
        break;
        double x1,x2,x3,x4;
        x1=dis(a,c);
        x2=dis(a,d);
        x3=dis(b,c);
        x4=dis(b,d);
        double min1;
        min1=min(x1,min(x2,min(x3,x4)));
        if(min1==x1)
        {
          p=(a.x+c.x)/2.0;
          q=(a.y+c.y)/2.0;
        }
        else
        {
            if(min1==x2)
            {
              p=(a.x+d.x)/2.0;
              q=(a.y+d.y)/2.0;
            }
            else
            {
                if(min1==x3)
                {p=(b.x+c.x)/2.0;
                q=(b.y+c.y)/2.0;}
                else
                {
                    p=(b.x+d.x)/2.0;
                   q=(b.y+d.y)/2.0;
                }
            }


        }
        r=min1/2.0+0.001;
        printf("%lf %lf %lf\n",p,q,r);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值